@frak-labs/nexus-sdk 0.0.15 → 0.0.17
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/dist/{NexusContext-CSlCNW-G.d.cts → FrakContext-LbQht1ep.d.cts} +2 -2
- package/dist/{NexusContext-CSlCNW-G.d.ts → FrakContext-LbQht1ep.d.ts} +2 -2
- package/dist/bundle/bundle.js +3 -3
- package/dist/{chunk-KEATMEOW.cjs → chunk-6GPWXPN4.cjs} +26 -23
- package/dist/{chunk-C25NTD45.cjs → chunk-A3XYA7S7.cjs} +28 -14
- package/dist/{chunk-2LAGZ6S5.js → chunk-B75G6TB3.js} +38 -30
- package/dist/{chunk-VMNURFPI.js → chunk-BP7RT2HB.js} +19 -16
- package/dist/{chunk-4ADWI2GG.cjs → chunk-ES3EBWJ6.cjs} +18 -18
- package/dist/{chunk-4LT3U3H4.cjs → chunk-H7YKYMTC.cjs} +41 -33
- package/dist/{chunk-K4FOGADW.js → chunk-HY6YATLS.js} +3 -1
- package/dist/{chunk-I47XQDS3.js → chunk-TIKEZMSD.js} +16 -2
- package/dist/{chunk-DILTMQBI.cjs → chunk-UFJ7W6CQ.cjs} +3 -1
- package/dist/{chunk-ARQTOP44.js → chunk-VXVUPIW7.js} +1 -1
- package/dist/{client-B3Guoe3I.d.ts → client-ALy_TEwJ.d.ts} +28 -8
- package/dist/{client-Of9uIxuI.d.cts → client-DaEox5q4.d.cts} +28 -8
- package/dist/core/actions/index.cjs +5 -5
- package/dist/core/actions/index.d.cts +6 -7
- package/dist/core/actions/index.d.ts +6 -7
- package/dist/core/actions/index.js +4 -4
- package/dist/core/index.cjs +10 -4
- package/dist/core/index.d.cts +41 -9
- package/dist/core/index.d.ts +41 -9
- package/dist/core/index.js +11 -5
- package/dist/core/interactions/index.cjs +5 -3
- package/dist/core/interactions/index.d.cts +9 -1
- package/dist/core/interactions/index.d.ts +9 -1
- package/dist/core/interactions/index.js +6 -4
- package/dist/react/index.cjs +34 -34
- package/dist/react/index.d.cts +3 -3
- package/dist/react/index.d.ts +3 -3
- package/dist/react/index.js +16 -16
- package/dist/{sendTransaction-3d8jO9CJ.d.ts → sendTransaction-BOd-pvXr.d.ts} +2 -2
- package/dist/{sendTransaction-Cz6FoB9_.d.cts → sendTransaction-MhdJPTWd.d.cts} +2 -2
- package/package.json +3 -3
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
__publicField
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-HY6YATLS.js";
|
|
4
4
|
|
|
5
5
|
// src/core/types/rpc/error.ts
|
|
6
6
|
var FrakRpcError = class extends Error {
|
|
@@ -37,6 +37,28 @@ var RpcErrorCodes = {
|
|
|
37
37
|
serverErrorForInteractionDelegation: -32006
|
|
38
38
|
};
|
|
39
39
|
|
|
40
|
+
// src/core/utils/Deferred.ts
|
|
41
|
+
var Deferred = class {
|
|
42
|
+
constructor() {
|
|
43
|
+
__publicField(this, "_promise");
|
|
44
|
+
__publicField(this, "_resolve");
|
|
45
|
+
__publicField(this, "_reject");
|
|
46
|
+
__publicField(this, "resolve", (value) => {
|
|
47
|
+
this._resolve?.(value);
|
|
48
|
+
});
|
|
49
|
+
__publicField(this, "reject", (reason) => {
|
|
50
|
+
this._reject?.(reason);
|
|
51
|
+
});
|
|
52
|
+
this._promise = new Promise((resolve, reject) => {
|
|
53
|
+
this._resolve = resolve;
|
|
54
|
+
this._reject = reject;
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
get promise() {
|
|
58
|
+
return this._promise;
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
|
|
40
62
|
// src/core/utils/compression/compress.ts
|
|
41
63
|
import { compressToBase64 } from "async-lz-string";
|
|
42
64
|
import { sha256 } from "js-sha256";
|
|
@@ -104,7 +126,7 @@ async function decompressJson(data) {
|
|
|
104
126
|
try {
|
|
105
127
|
return JSON.parse(decompressed);
|
|
106
128
|
} catch (e) {
|
|
107
|
-
console.error("Invalid compressed data", e);
|
|
129
|
+
console.error("Invalid compressed data", { e, decompressed });
|
|
108
130
|
return null;
|
|
109
131
|
}
|
|
110
132
|
}
|
|
@@ -164,14 +186,14 @@ function changeIframeVisibility({
|
|
|
164
186
|
iframe.style.pointerEvents = "auto";
|
|
165
187
|
}
|
|
166
188
|
|
|
167
|
-
// src/core/utils/
|
|
168
|
-
var contextKey = "
|
|
189
|
+
// src/core/utils/FrakContext.ts
|
|
190
|
+
var contextKey = "fCtx";
|
|
169
191
|
async function parse({ url }) {
|
|
170
192
|
if (!url) return null;
|
|
171
193
|
const urlObj = new URL(url);
|
|
172
194
|
const nexusContext = urlObj.searchParams.get(contextKey);
|
|
173
195
|
if (!nexusContext) return null;
|
|
174
|
-
const parsedContext = await decompressJson(nexusContext);
|
|
196
|
+
const parsedContext = await decompressJson(decodeURIComponent(nexusContext));
|
|
175
197
|
if (!parsedContext) return null;
|
|
176
198
|
return parsedContext;
|
|
177
199
|
}
|
|
@@ -185,7 +207,12 @@ async function update({
|
|
|
185
207
|
const compressedContext = await compressJson(mergedContext);
|
|
186
208
|
if (!compressedContext) return;
|
|
187
209
|
const urlObj = new URL(url);
|
|
188
|
-
urlObj.searchParams.set(contextKey, compressedContext);
|
|
210
|
+
urlObj.searchParams.set(contextKey, encodeURIComponent(compressedContext));
|
|
211
|
+
return urlObj.toString();
|
|
212
|
+
}
|
|
213
|
+
function remove(url) {
|
|
214
|
+
const urlObj = new URL(url);
|
|
215
|
+
urlObj.searchParams.delete(contextKey);
|
|
189
216
|
return urlObj.toString();
|
|
190
217
|
}
|
|
191
218
|
async function replaceUrl({
|
|
@@ -203,34 +230,13 @@ async function replaceUrl({
|
|
|
203
230
|
if (!newUrl) return;
|
|
204
231
|
window.history.replaceState(null, "", newUrl.toString());
|
|
205
232
|
}
|
|
206
|
-
var
|
|
233
|
+
var FrakContextManager = {
|
|
207
234
|
parse,
|
|
208
235
|
update,
|
|
236
|
+
remove,
|
|
209
237
|
replaceUrl
|
|
210
238
|
};
|
|
211
239
|
|
|
212
|
-
// src/core/utils/Deferred.ts
|
|
213
|
-
var Deferred = class {
|
|
214
|
-
constructor() {
|
|
215
|
-
__publicField(this, "_promise");
|
|
216
|
-
__publicField(this, "_resolve");
|
|
217
|
-
__publicField(this, "_reject");
|
|
218
|
-
__publicField(this, "resolve", (value) => {
|
|
219
|
-
this._resolve?.(value);
|
|
220
|
-
});
|
|
221
|
-
__publicField(this, "reject", (reason) => {
|
|
222
|
-
this._reject?.(reason);
|
|
223
|
-
});
|
|
224
|
-
this._promise = new Promise((resolve, reject) => {
|
|
225
|
-
this._resolve = resolve;
|
|
226
|
-
this._reject = reject;
|
|
227
|
-
});
|
|
228
|
-
}
|
|
229
|
-
get promise() {
|
|
230
|
-
return this._promise;
|
|
231
|
-
}
|
|
232
|
-
};
|
|
233
|
-
|
|
234
240
|
export {
|
|
235
241
|
FrakRpcError,
|
|
236
242
|
InternalError,
|
|
@@ -238,9 +244,11 @@ export {
|
|
|
238
244
|
RpcErrorCodes,
|
|
239
245
|
Deferred,
|
|
240
246
|
hashAndCompressData,
|
|
247
|
+
compressJson,
|
|
241
248
|
decompressDataAndCheckHash,
|
|
249
|
+
decompressJson,
|
|
242
250
|
baseIframeProps,
|
|
243
251
|
createIframe,
|
|
244
252
|
changeIframeVisibility,
|
|
245
|
-
|
|
253
|
+
FrakContextManager
|
|
246
254
|
};
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import {
|
|
2
2
|
Deferred,
|
|
3
|
+
FrakContextManager,
|
|
3
4
|
FrakRpcError,
|
|
4
|
-
NexusContextManager,
|
|
5
5
|
RpcErrorCodes
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-B75G6TB3.js";
|
|
7
7
|
import {
|
|
8
8
|
ReferralInteractionEncoder
|
|
9
|
-
} from "./chunk-
|
|
9
|
+
} from "./chunk-TIKEZMSD.js";
|
|
10
10
|
|
|
11
11
|
// src/core/actions/watchWalletStatus.ts
|
|
12
12
|
function watchWalletStatus(client, callback) {
|
|
@@ -104,15 +104,15 @@ async function walletStatus(client, callback) {
|
|
|
104
104
|
import { isAddressEqual } from "viem";
|
|
105
105
|
async function processReferral(client, {
|
|
106
106
|
walletStatus: walletStatus2,
|
|
107
|
-
|
|
107
|
+
frakContext,
|
|
108
108
|
modalConfig,
|
|
109
109
|
productId
|
|
110
110
|
}) {
|
|
111
111
|
try {
|
|
112
|
-
let currentWallet =
|
|
113
|
-
if (!
|
|
112
|
+
let currentWallet = walletStatus2?.wallet;
|
|
113
|
+
if (!frakContext?.r) {
|
|
114
114
|
if (currentWallet) {
|
|
115
|
-
await
|
|
115
|
+
await FrakContextManager.replaceUrl({
|
|
116
116
|
url: window.location?.href,
|
|
117
117
|
context: { r: currentWallet }
|
|
118
118
|
});
|
|
@@ -125,17 +125,23 @@ async function processReferral(client, {
|
|
|
125
125
|
walletStatus: walletStatus2
|
|
126
126
|
});
|
|
127
127
|
}
|
|
128
|
-
if (currentWallet && isAddressEqual(
|
|
128
|
+
if (currentWallet && isAddressEqual(frakContext.r, currentWallet)) {
|
|
129
129
|
return "self-referral";
|
|
130
130
|
}
|
|
131
|
+
if (!walletStatus2?.interactionSession) {
|
|
132
|
+
currentWallet = await ensureWalletConnected(client, {
|
|
133
|
+
modalConfig,
|
|
134
|
+
walletStatus: walletStatus2
|
|
135
|
+
});
|
|
136
|
+
}
|
|
131
137
|
if (currentWallet) {
|
|
132
|
-
await
|
|
138
|
+
await FrakContextManager.replaceUrl({
|
|
133
139
|
url: window.location?.href,
|
|
134
140
|
context: { r: currentWallet }
|
|
135
141
|
});
|
|
136
142
|
}
|
|
137
143
|
const interaction = ReferralInteractionEncoder.referred({
|
|
138
|
-
referrer:
|
|
144
|
+
referrer: frakContext.r
|
|
139
145
|
});
|
|
140
146
|
await sendInteraction(client, { productId, interaction });
|
|
141
147
|
return "success";
|
|
@@ -143,14 +149,11 @@ async function processReferral(client, {
|
|
|
143
149
|
return mapErrorToState(error);
|
|
144
150
|
}
|
|
145
151
|
}
|
|
146
|
-
function getCurrentWallet(walletStatus2) {
|
|
147
|
-
return walletStatus2?.key === "connected" ? walletStatus2.wallet : void 0;
|
|
148
|
-
}
|
|
149
152
|
async function ensureWalletConnected(client, {
|
|
150
153
|
modalConfig,
|
|
151
154
|
walletStatus: walletStatus2
|
|
152
155
|
}) {
|
|
153
|
-
if (walletStatus2?.
|
|
156
|
+
if (!walletStatus2?.interactionSession) {
|
|
154
157
|
if (!modalConfig) {
|
|
155
158
|
return void 0;
|
|
156
159
|
}
|
|
@@ -178,14 +181,14 @@ async function referralInteraction(client, {
|
|
|
178
181
|
productId,
|
|
179
182
|
modalConfig
|
|
180
183
|
} = {}) {
|
|
181
|
-
const
|
|
184
|
+
const frakContext = await FrakContextManager.parse({
|
|
182
185
|
url: window.location.href
|
|
183
186
|
});
|
|
184
187
|
const currentWalletStatus = await walletStatus(client);
|
|
185
188
|
try {
|
|
186
189
|
return await processReferral(client, {
|
|
187
190
|
walletStatus: currentWalletStatus,
|
|
188
|
-
|
|
191
|
+
frakContext,
|
|
189
192
|
modalConfig,
|
|
190
193
|
productId
|
|
191
194
|
});
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
|
|
7
7
|
|
|
8
8
|
|
|
9
|
-
var
|
|
9
|
+
var _chunkH7YKYMTCcjs = require('./chunk-H7YKYMTC.cjs');
|
|
10
10
|
|
|
11
11
|
// src/core/utils/constants.ts
|
|
12
12
|
var BACKUP_KEY = "nexus-wallet-backup";
|
|
@@ -31,7 +31,7 @@ function createIFrameChannelManager() {
|
|
|
31
31
|
function createIFrameLifecycleManager({
|
|
32
32
|
iframe
|
|
33
33
|
}) {
|
|
34
|
-
const isConnectedDeferred = new (0,
|
|
34
|
+
const isConnectedDeferred = new (0, _chunkH7YKYMTCcjs.Deferred)();
|
|
35
35
|
const handler = async (messageEvent) => {
|
|
36
36
|
switch (messageEvent.iframeLifecycle) {
|
|
37
37
|
// Resolve the isConnected promise
|
|
@@ -53,7 +53,7 @@ function createIFrameLifecycleManager({
|
|
|
53
53
|
// Change iframe visibility
|
|
54
54
|
case "show":
|
|
55
55
|
case "hide":
|
|
56
|
-
|
|
56
|
+
_chunkH7YKYMTCcjs.changeIframeVisibility.call(void 0, {
|
|
57
57
|
iframe,
|
|
58
58
|
isVisible: messageEvent.iframeLifecycle === "show"
|
|
59
59
|
});
|
|
@@ -74,14 +74,14 @@ function createIFrameMessageHandler({
|
|
|
74
74
|
iframeLifecycleManager
|
|
75
75
|
}) {
|
|
76
76
|
if (typeof window === "undefined") {
|
|
77
|
-
throw new (0,
|
|
78
|
-
|
|
77
|
+
throw new (0, _chunkH7YKYMTCcjs.FrakRpcError)(
|
|
78
|
+
_chunkH7YKYMTCcjs.RpcErrorCodes.configError,
|
|
79
79
|
"iframe client should be used in the browser"
|
|
80
80
|
);
|
|
81
81
|
}
|
|
82
82
|
if (!iframe.contentWindow) {
|
|
83
|
-
throw new (0,
|
|
84
|
-
|
|
83
|
+
throw new (0, _chunkH7YKYMTCcjs.FrakRpcError)(
|
|
84
|
+
_chunkH7YKYMTCcjs.RpcErrorCodes.configError,
|
|
85
85
|
"The iframe does not have a product window"
|
|
86
86
|
);
|
|
87
87
|
}
|
|
@@ -141,17 +141,17 @@ function createIFrameNexusClient({
|
|
|
141
141
|
const request = async (args) => {
|
|
142
142
|
const isConnected = await lifecycleManager.isConnected;
|
|
143
143
|
if (!isConnected) {
|
|
144
|
-
throw new (0,
|
|
145
|
-
|
|
144
|
+
throw new (0, _chunkH7YKYMTCcjs.FrakRpcError)(
|
|
145
|
+
_chunkH7YKYMTCcjs.RpcErrorCodes.clientNotConnected,
|
|
146
146
|
"The iframe provider isn't connected yet"
|
|
147
147
|
);
|
|
148
148
|
}
|
|
149
|
-
const result = new (0,
|
|
149
|
+
const result = new (0, _chunkH7YKYMTCcjs.Deferred)();
|
|
150
150
|
const channelId = channelManager.createChannel(async (message) => {
|
|
151
|
-
const decompressed = await
|
|
151
|
+
const decompressed = await _chunkH7YKYMTCcjs.decompressDataAndCheckHash.call(void 0, message.data);
|
|
152
152
|
if (decompressed.error) {
|
|
153
153
|
result.reject(
|
|
154
|
-
new (0,
|
|
154
|
+
new (0, _chunkH7YKYMTCcjs.FrakRpcError)(
|
|
155
155
|
decompressed.error.code,
|
|
156
156
|
decompressed.error.message,
|
|
157
157
|
_optionalChain([decompressed, 'access', _ => _.error, 'optionalAccess', _2 => _2.data])
|
|
@@ -162,7 +162,7 @@ function createIFrameNexusClient({
|
|
|
162
162
|
}
|
|
163
163
|
channelManager.removeChannel(channelId);
|
|
164
164
|
});
|
|
165
|
-
const compressedMessage = await
|
|
165
|
+
const compressedMessage = await _chunkH7YKYMTCcjs.hashAndCompressData.call(void 0, args);
|
|
166
166
|
messageHandler.sendEvent({
|
|
167
167
|
id: channelId,
|
|
168
168
|
topic: args.method,
|
|
@@ -173,20 +173,20 @@ function createIFrameNexusClient({
|
|
|
173
173
|
const listenerRequest = async (args, callback) => {
|
|
174
174
|
const isConnected = await lifecycleManager.isConnected;
|
|
175
175
|
if (!isConnected) {
|
|
176
|
-
throw new (0,
|
|
177
|
-
|
|
176
|
+
throw new (0, _chunkH7YKYMTCcjs.FrakRpcError)(
|
|
177
|
+
_chunkH7YKYMTCcjs.RpcErrorCodes.clientNotConnected,
|
|
178
178
|
"The iframe provider isn't connected yet"
|
|
179
179
|
);
|
|
180
180
|
}
|
|
181
181
|
const channelId = channelManager.createChannel(async (message) => {
|
|
182
|
-
const decompressed = await
|
|
182
|
+
const decompressed = await _chunkH7YKYMTCcjs.decompressDataAndCheckHash.call(void 0, message.data);
|
|
183
183
|
if (decompressed.result) {
|
|
184
184
|
callback(decompressed.result);
|
|
185
185
|
} else {
|
|
186
|
-
throw new (0,
|
|
186
|
+
throw new (0, _chunkH7YKYMTCcjs.InternalError)("No valid result in the response");
|
|
187
187
|
}
|
|
188
188
|
});
|
|
189
|
-
const compressedMessage = await
|
|
189
|
+
const compressedMessage = await _chunkH7YKYMTCcjs.hashAndCompressData.call(void 0, args);
|
|
190
190
|
messageHandler.sendEvent({
|
|
191
191
|
id: channelId,
|
|
192
192
|
topic: args.method,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var _chunkUFJ7W6CQcjs = require('./chunk-UFJ7W6CQ.cjs');
|
|
4
4
|
|
|
5
5
|
// src/core/types/rpc/error.ts
|
|
6
6
|
var FrakRpcError = class extends Error {
|
|
@@ -37,6 +37,28 @@ var RpcErrorCodes = {
|
|
|
37
37
|
serverErrorForInteractionDelegation: -32006
|
|
38
38
|
};
|
|
39
39
|
|
|
40
|
+
// src/core/utils/Deferred.ts
|
|
41
|
+
var Deferred = class {
|
|
42
|
+
constructor() {
|
|
43
|
+
_chunkUFJ7W6CQcjs.__publicField.call(void 0, this, "_promise");
|
|
44
|
+
_chunkUFJ7W6CQcjs.__publicField.call(void 0, this, "_resolve");
|
|
45
|
+
_chunkUFJ7W6CQcjs.__publicField.call(void 0, this, "_reject");
|
|
46
|
+
_chunkUFJ7W6CQcjs.__publicField.call(void 0, this, "resolve", (value) => {
|
|
47
|
+
_optionalChain([this, 'access', _2 => _2._resolve, 'optionalCall', _3 => _3(value)]);
|
|
48
|
+
});
|
|
49
|
+
_chunkUFJ7W6CQcjs.__publicField.call(void 0, this, "reject", (reason) => {
|
|
50
|
+
_optionalChain([this, 'access', _4 => _4._reject, 'optionalCall', _5 => _5(reason)]);
|
|
51
|
+
});
|
|
52
|
+
this._promise = new Promise((resolve, reject) => {
|
|
53
|
+
this._resolve = resolve;
|
|
54
|
+
this._reject = reject;
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
get promise() {
|
|
58
|
+
return this._promise;
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
|
|
40
62
|
// src/core/utils/compression/compress.ts
|
|
41
63
|
var _asynclzstring = require('async-lz-string');
|
|
42
64
|
var _jssha256 = require('js-sha256');
|
|
@@ -61,7 +83,7 @@ async function compressJson(data) {
|
|
|
61
83
|
|
|
62
84
|
|
|
63
85
|
async function decompressDataAndCheckHash(compressedData) {
|
|
64
|
-
if (!(_optionalChain([compressedData, 'optionalAccess',
|
|
86
|
+
if (!(_optionalChain([compressedData, 'optionalAccess', _6 => _6.compressed]) && _optionalChain([compressedData, 'optionalAccess', _7 => _7.compressedHash]))) {
|
|
65
87
|
throw new FrakRpcError(
|
|
66
88
|
RpcErrorCodes.corruptedResponse,
|
|
67
89
|
"Missing compressed data"
|
|
@@ -76,7 +98,7 @@ async function decompressDataAndCheckHash(compressedData) {
|
|
|
76
98
|
"Invalid compressed data"
|
|
77
99
|
);
|
|
78
100
|
}
|
|
79
|
-
if (!_optionalChain([parsedData, 'optionalAccess',
|
|
101
|
+
if (!_optionalChain([parsedData, 'optionalAccess', _8 => _8.validationHash])) {
|
|
80
102
|
throw new FrakRpcError(
|
|
81
103
|
RpcErrorCodes.corruptedResponse,
|
|
82
104
|
"Missing validation hash"
|
|
@@ -104,7 +126,7 @@ async function decompressJson(data) {
|
|
|
104
126
|
try {
|
|
105
127
|
return JSON.parse(decompressed);
|
|
106
128
|
} catch (e) {
|
|
107
|
-
console.error("Invalid compressed data", e);
|
|
129
|
+
console.error("Invalid compressed data", { e, decompressed });
|
|
108
130
|
return null;
|
|
109
131
|
}
|
|
110
132
|
}
|
|
@@ -139,7 +161,7 @@ function createIframe({
|
|
|
139
161
|
changeIframeVisibility({ iframe, isVisible: false });
|
|
140
162
|
document.body.appendChild(iframe);
|
|
141
163
|
return new Promise((resolve) => {
|
|
142
|
-
_optionalChain([iframe, 'optionalAccess',
|
|
164
|
+
_optionalChain([iframe, 'optionalAccess', _9 => _9.addEventListener, 'call', _10 => _10("load", () => resolve(iframe))]);
|
|
143
165
|
iframe.src = `${walletBaseUrl}/listener`;
|
|
144
166
|
});
|
|
145
167
|
}
|
|
@@ -164,14 +186,14 @@ function changeIframeVisibility({
|
|
|
164
186
|
iframe.style.pointerEvents = "auto";
|
|
165
187
|
}
|
|
166
188
|
|
|
167
|
-
// src/core/utils/
|
|
168
|
-
var contextKey = "
|
|
189
|
+
// src/core/utils/FrakContext.ts
|
|
190
|
+
var contextKey = "fCtx";
|
|
169
191
|
async function parse({ url }) {
|
|
170
192
|
if (!url) return null;
|
|
171
193
|
const urlObj = new URL(url);
|
|
172
194
|
const nexusContext = urlObj.searchParams.get(contextKey);
|
|
173
195
|
if (!nexusContext) return null;
|
|
174
|
-
const parsedContext = await decompressJson(nexusContext);
|
|
196
|
+
const parsedContext = await decompressJson(decodeURIComponent(nexusContext));
|
|
175
197
|
if (!parsedContext) return null;
|
|
176
198
|
return parsedContext;
|
|
177
199
|
}
|
|
@@ -185,14 +207,19 @@ async function update({
|
|
|
185
207
|
const compressedContext = await compressJson(mergedContext);
|
|
186
208
|
if (!compressedContext) return;
|
|
187
209
|
const urlObj = new URL(url);
|
|
188
|
-
urlObj.searchParams.set(contextKey, compressedContext);
|
|
210
|
+
urlObj.searchParams.set(contextKey, encodeURIComponent(compressedContext));
|
|
211
|
+
return urlObj.toString();
|
|
212
|
+
}
|
|
213
|
+
function remove(url) {
|
|
214
|
+
const urlObj = new URL(url);
|
|
215
|
+
urlObj.searchParams.delete(contextKey);
|
|
189
216
|
return urlObj.toString();
|
|
190
217
|
}
|
|
191
218
|
async function replaceUrl({
|
|
192
219
|
url,
|
|
193
220
|
context
|
|
194
221
|
}) {
|
|
195
|
-
if (!_optionalChain([window, 'access',
|
|
222
|
+
if (!_optionalChain([window, 'access', _11 => _11.location, 'optionalAccess', _12 => _12.href]) || typeof window === "undefined") {
|
|
196
223
|
console.error("No window found, can't update context");
|
|
197
224
|
return;
|
|
198
225
|
}
|
|
@@ -203,33 +230,13 @@ async function replaceUrl({
|
|
|
203
230
|
if (!newUrl) return;
|
|
204
231
|
window.history.replaceState(null, "", newUrl.toString());
|
|
205
232
|
}
|
|
206
|
-
var
|
|
233
|
+
var FrakContextManager = {
|
|
207
234
|
parse,
|
|
208
235
|
update,
|
|
236
|
+
remove,
|
|
209
237
|
replaceUrl
|
|
210
238
|
};
|
|
211
239
|
|
|
212
|
-
// src/core/utils/Deferred.ts
|
|
213
|
-
var Deferred = class {
|
|
214
|
-
constructor() {
|
|
215
|
-
_chunkDILTMQBIcjs.__publicField.call(void 0, this, "_promise");
|
|
216
|
-
_chunkDILTMQBIcjs.__publicField.call(void 0, this, "_resolve");
|
|
217
|
-
_chunkDILTMQBIcjs.__publicField.call(void 0, this, "_reject");
|
|
218
|
-
_chunkDILTMQBIcjs.__publicField.call(void 0, this, "resolve", (value) => {
|
|
219
|
-
_optionalChain([this, 'access', _9 => _9._resolve, 'optionalCall', _10 => _10(value)]);
|
|
220
|
-
});
|
|
221
|
-
_chunkDILTMQBIcjs.__publicField.call(void 0, this, "reject", (reason) => {
|
|
222
|
-
_optionalChain([this, 'access', _11 => _11._reject, 'optionalCall', _12 => _12(reason)]);
|
|
223
|
-
});
|
|
224
|
-
this._promise = new Promise((resolve, reject) => {
|
|
225
|
-
this._resolve = resolve;
|
|
226
|
-
this._reject = reject;
|
|
227
|
-
});
|
|
228
|
-
}
|
|
229
|
-
get promise() {
|
|
230
|
-
return this._promise;
|
|
231
|
-
}
|
|
232
|
-
};
|
|
233
240
|
|
|
234
241
|
|
|
235
242
|
|
|
@@ -243,4 +250,5 @@ var Deferred = class {
|
|
|
243
250
|
|
|
244
251
|
|
|
245
252
|
|
|
246
|
-
|
|
253
|
+
|
|
254
|
+
exports.FrakRpcError = FrakRpcError; exports.InternalError = InternalError; exports.ClientNotFound = ClientNotFound; exports.RpcErrorCodes = RpcErrorCodes; exports.Deferred = Deferred; exports.hashAndCompressData = hashAndCompressData; exports.compressJson = compressJson; exports.decompressDataAndCheckHash = decompressDataAndCheckHash; exports.decompressJson = decompressJson; exports.baseIframeProps = baseIframeProps; exports.createIframe = createIframe; exports.changeIframeVisibility = changeIframeVisibility; exports.FrakContextManager = FrakContextManager;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
interactionTypes,
|
|
3
3
|
productTypes
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-HY6YATLS.js";
|
|
5
5
|
|
|
6
6
|
// src/core/interactions/pressEncoder.ts
|
|
7
7
|
import { concatHex, pad, toHex } from "viem";
|
|
@@ -93,8 +93,22 @@ var PurchaseInteractionEncoder = {
|
|
|
93
93
|
completedPurchase
|
|
94
94
|
};
|
|
95
95
|
|
|
96
|
+
// src/core/interactions/webshopEncoder.ts
|
|
97
|
+
import { concatHex as concatHex4, toHex as toHex4 } from "viem";
|
|
98
|
+
function open() {
|
|
99
|
+
const interactionData = concatHex4([interactionTypes.webshop.open, "0x"]);
|
|
100
|
+
return {
|
|
101
|
+
handlerTypeDenominator: toHex4(productTypes.webshop),
|
|
102
|
+
interactionData
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
var WebShopInteractionEncoder = {
|
|
106
|
+
open
|
|
107
|
+
};
|
|
108
|
+
|
|
96
109
|
export {
|
|
97
110
|
PressInteractionEncoder,
|
|
98
111
|
ReferralInteractionEncoder,
|
|
99
|
-
PurchaseInteractionEncoder
|
|
112
|
+
PurchaseInteractionEncoder,
|
|
113
|
+
WebShopInteractionEncoder
|
|
100
114
|
};
|
|
@@ -67,6 +67,7 @@ type SsoMetadata = {
|
|
|
67
67
|
type OpenSsoParamsType = {
|
|
68
68
|
redirectUrl?: string;
|
|
69
69
|
directExit?: boolean;
|
|
70
|
+
lang?: "en" | "fr";
|
|
70
71
|
metadata: SsoMetadata;
|
|
71
72
|
};
|
|
72
73
|
|
|
@@ -125,7 +126,6 @@ type SiweAuthenticateModalStepType = GenericModalStepType<"siweAuthenticate", {
|
|
|
125
126
|
|
|
126
127
|
/**
|
|
127
128
|
* Generic format representing a tx to be sent
|
|
128
|
-
* todo: exploit the EIP-5792 here? https://eips.ethereum.org/EIPS/eip-5792
|
|
129
129
|
*/
|
|
130
130
|
type SendTransactionTxType = Readonly<{
|
|
131
131
|
to: Address;
|
|
@@ -155,20 +155,29 @@ type OpenInteractionSessionReturnType = Readonly<{
|
|
|
155
155
|
type OpenInteractionSessionModalStepType = GenericModalStepType<"openSession", object, OpenInteractionSessionReturnType>;
|
|
156
156
|
|
|
157
157
|
/**
|
|
158
|
-
*
|
|
158
|
+
* The final modal step type (displayed on success or dimissed)
|
|
159
159
|
*/
|
|
160
|
-
type
|
|
161
|
-
|
|
160
|
+
type FinalModalStepType = GenericModalStepType<"final", {
|
|
161
|
+
dismissedMetadata?: ModalStepMetadata["metadata"];
|
|
162
|
+
action: FinalActionType;
|
|
163
|
+
autoSkip?: boolean;
|
|
164
|
+
}, object>;
|
|
165
|
+
type FinalActionType = {
|
|
166
|
+
key: "sharing";
|
|
167
|
+
options?: {
|
|
162
168
|
popupTitle?: string;
|
|
163
169
|
text?: string;
|
|
164
170
|
link?: string;
|
|
165
171
|
};
|
|
166
|
-
}
|
|
172
|
+
} | {
|
|
173
|
+
key: "reward";
|
|
174
|
+
options?: never;
|
|
175
|
+
};
|
|
167
176
|
|
|
168
177
|
/**
|
|
169
178
|
* Generic type of steps we will display in the modal to the end user
|
|
170
179
|
*/
|
|
171
|
-
type ModalStepTypes = LoginModalStepType | SiweAuthenticateModalStepType | SendTransactionModalStepType | OpenInteractionSessionModalStepType |
|
|
180
|
+
type ModalStepTypes = LoginModalStepType | SiweAuthenticateModalStepType | SendTransactionModalStepType | OpenInteractionSessionModalStepType | FinalModalStepType;
|
|
172
181
|
/**
|
|
173
182
|
* Type for the result of a modal request
|
|
174
183
|
*/
|
|
@@ -194,7 +203,14 @@ type ModalRpcMetadata = Readonly<{
|
|
|
194
203
|
icon?: string;
|
|
195
204
|
};
|
|
196
205
|
context?: string;
|
|
197
|
-
|
|
206
|
+
lang?: "en" | "fr";
|
|
207
|
+
} & ({
|
|
208
|
+
isDismissible: true;
|
|
209
|
+
dismissActionTxt?: string;
|
|
210
|
+
} | {
|
|
211
|
+
isDismissible?: false;
|
|
212
|
+
dismissActionTxt?: never;
|
|
213
|
+
})>;
|
|
198
214
|
/**
|
|
199
215
|
* Generic params used to display modals
|
|
200
216
|
*/
|
|
@@ -207,6 +223,7 @@ type WalletStatusReturnType = Readonly<WalletConnected | WalletNotConnected>;
|
|
|
207
223
|
type WalletConnected = {
|
|
208
224
|
key: "connected";
|
|
209
225
|
wallet: Address;
|
|
226
|
+
interactionToken?: string;
|
|
210
227
|
interactionSession?: {
|
|
211
228
|
startTimestamp: number;
|
|
212
229
|
endTimestamp: number;
|
|
@@ -214,6 +231,9 @@ type WalletConnected = {
|
|
|
214
231
|
};
|
|
215
232
|
type WalletNotConnected = {
|
|
216
233
|
key: "not-connected";
|
|
234
|
+
wallet?: never;
|
|
235
|
+
interactionToken?: never;
|
|
236
|
+
interactionSession?: never;
|
|
217
237
|
};
|
|
218
238
|
|
|
219
239
|
/**
|
|
@@ -360,4 +380,4 @@ type NexusClient = {
|
|
|
360
380
|
config: NexusWalletSdkConfig;
|
|
361
381
|
} & IFrameTransport;
|
|
362
382
|
|
|
363
|
-
export type { ClientLifecycleEvent as C, DisplayModalParamsType as D, ExtractedParametersFromRpc as E, IFrameRpcSchema as I, LoginModalStepType as L, ModalStepTypes as M, NexusWalletSdkConfig as N, OpenSsoParamsType as O, RpcResponse as R,
|
|
383
|
+
export type { ClientLifecycleEvent as C, DisplayModalParamsType as D, ExtractedParametersFromRpc as E, FinalModalStepType as F, IFrameRpcSchema as I, LoginModalStepType as L, ModalStepTypes as M, NexusWalletSdkConfig as N, OpenSsoParamsType as O, RpcResponse as R, SsoMetadata as S, WalletStatusReturnType as W, NexusClient as a, ModalRpcMetadata as b, ModalRpcStepsInput as c, ModalRpcStepsResultType as d, ModalStepMetadata as e, SiweAuthenticateModalStepType as f, SiweAuthenticationParams as g, SiweAuthenticateReturnType as h, SendTransactionTxType as i, SendTransactionModalStepType as j, SendTransactionReturnType as k, OpenInteractionSessionReturnType as l, OpenInteractionSessionModalStepType as m, FinalActionType as n, IFrameTransport as o, IFrameRpcEvent as p, IFrameEvent as q, IFrameLifecycleEvent as r, ExtractedReturnTypeFromRpc as s };
|