@frak-labs/nexus-sdk 0.0.3-alpha → 0.0.6
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/{chunk-N4N55SQ6.cjs → chunk-2XUJYDD3.cjs} +2 -2
- package/dist/chunk-3LF3FGI6.cjs +78 -0
- package/dist/{chunk-6ZFDRVV6.js → chunk-5QWG35A2.js} +2 -2
- package/dist/chunk-DI2REDPX.js +78 -0
- package/dist/chunk-JXQKTLEE.cjs +171 -0
- package/dist/chunk-OXP3VK26.js +171 -0
- package/dist/{client-CkvisXxD.d.cts → client-DWLJ8zR-.d.cts} +10 -7
- package/dist/{client-CkvisXxD.d.ts → client-DWLJ8zR-.d.ts} +10 -7
- package/dist/core/actions/index.cjs +3 -65
- package/dist/core/actions/index.d.cts +4 -37
- package/dist/core/actions/index.d.ts +4 -37
- package/dist/core/actions/index.js +7 -69
- package/dist/core/index.cjs +22 -179
- package/dist/core/index.d.cts +3 -3
- package/dist/core/index.d.ts +3 -3
- package/dist/core/index.js +4 -161
- package/dist/react/index.cjs +169 -0
- package/dist/react/index.d.cts +99 -0
- package/dist/react/index.d.ts +99 -0
- package/dist/react/index.js +169 -0
- package/dist/watchUnlockStatus--7dFtOJr.d.ts +38 -0
- package/dist/watchUnlockStatus-B4kRztOM.d.cts +38 -0
- package/package.json +10 -2
|
@@ -104,8 +104,8 @@ function getIFrameResponseKeyProvider(param) {
|
|
|
104
104
|
function createIframe({
|
|
105
105
|
walletBaseUrl
|
|
106
106
|
}) {
|
|
107
|
-
const
|
|
108
|
-
if (
|
|
107
|
+
const alreadyCreatedIFrame = document.querySelector("#nexus-wallet");
|
|
108
|
+
if (alreadyCreatedIFrame) {
|
|
109
109
|
return Promise.resolve(void 0);
|
|
110
110
|
}
|
|
111
111
|
const iframe = document.createElement("iframe");
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
var _chunk2XUJYDD3cjs = require('./chunk-2XUJYDD3.cjs');
|
|
7
|
+
|
|
8
|
+
// src/core/actions/getUnlockOptions.ts
|
|
9
|
+
function getArticleUnlockOptions(client, { articleId }) {
|
|
10
|
+
return client.request({
|
|
11
|
+
method: "frak_getArticleUnlockOptions",
|
|
12
|
+
params: [client.config.contentId, articleId]
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
// src/core/actions/watchUnlockStatus.ts
|
|
17
|
+
function watchUnlockStatus(client, { articleId }, callback) {
|
|
18
|
+
return client.listenerRequest(
|
|
19
|
+
{
|
|
20
|
+
method: "frak_listenToArticleUnlockStatus",
|
|
21
|
+
params: [client.config.contentId, articleId]
|
|
22
|
+
},
|
|
23
|
+
callback
|
|
24
|
+
);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// src/core/actions/watchWalletStatus.ts
|
|
28
|
+
function watchWalletStatus(client, callback) {
|
|
29
|
+
return client.listenerRequest(
|
|
30
|
+
{
|
|
31
|
+
method: "frak_listenToWalletStatus"
|
|
32
|
+
},
|
|
33
|
+
callback
|
|
34
|
+
);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// src/core/actions/startUnlock.ts
|
|
38
|
+
async function getStartArticleUnlockUrl(config, params) {
|
|
39
|
+
const { compressed, compressedHash } = await _chunk2XUJYDD3cjs.hashAndCompressData.call(void 0,
|
|
40
|
+
{
|
|
41
|
+
method: "frak_startArticleUnlock",
|
|
42
|
+
params: {
|
|
43
|
+
...params,
|
|
44
|
+
contentId: config.contentId,
|
|
45
|
+
contentTitle: config.contentTitle
|
|
46
|
+
}
|
|
47
|
+
},
|
|
48
|
+
_chunk2XUJYDD3cjs.redirectRequestKeyProvider
|
|
49
|
+
);
|
|
50
|
+
const outputUrl = new URL(config.walletUrl);
|
|
51
|
+
outputUrl.pathname = "/paywall";
|
|
52
|
+
outputUrl.searchParams.set("params", encodeURIComponent(compressed));
|
|
53
|
+
outputUrl.searchParams.set("hash", encodeURIComponent(compressedHash));
|
|
54
|
+
return outputUrl.toString();
|
|
55
|
+
}
|
|
56
|
+
async function decodeStartUnlockReturn({
|
|
57
|
+
result,
|
|
58
|
+
hash
|
|
59
|
+
}) {
|
|
60
|
+
const keyProvider = _chunk2XUJYDD3cjs.getRedirectResponseResponseKeyProvider.call(void 0,
|
|
61
|
+
"frak_startArticleUnlock"
|
|
62
|
+
);
|
|
63
|
+
return _chunk2XUJYDD3cjs.decompressDataAndCheckHash.call(void 0,
|
|
64
|
+
{
|
|
65
|
+
compressed: decodeURIComponent(result),
|
|
66
|
+
compressedHash: decodeURIComponent(hash)
|
|
67
|
+
},
|
|
68
|
+
keyProvider
|
|
69
|
+
);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
exports.getArticleUnlockOptions = getArticleUnlockOptions; exports.watchUnlockStatus = watchUnlockStatus; exports.watchWalletStatus = watchWalletStatus; exports.getStartArticleUnlockUrl = getStartArticleUnlockUrl; exports.decodeStartUnlockReturn = decodeStartUnlockReturn;
|
|
@@ -104,8 +104,8 @@ function getIFrameResponseKeyProvider(param) {
|
|
|
104
104
|
function createIframe({
|
|
105
105
|
walletBaseUrl
|
|
106
106
|
}) {
|
|
107
|
-
const
|
|
108
|
-
if (
|
|
107
|
+
const alreadyCreatedIFrame = document.querySelector("#nexus-wallet");
|
|
108
|
+
if (alreadyCreatedIFrame) {
|
|
109
109
|
return Promise.resolve(void 0);
|
|
110
110
|
}
|
|
111
111
|
const iframe = document.createElement("iframe");
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import {
|
|
2
|
+
decompressDataAndCheckHash,
|
|
3
|
+
getRedirectResponseResponseKeyProvider,
|
|
4
|
+
hashAndCompressData,
|
|
5
|
+
redirectRequestKeyProvider
|
|
6
|
+
} from "./chunk-5QWG35A2.js";
|
|
7
|
+
|
|
8
|
+
// src/core/actions/getUnlockOptions.ts
|
|
9
|
+
function getArticleUnlockOptions(client, { articleId }) {
|
|
10
|
+
return client.request({
|
|
11
|
+
method: "frak_getArticleUnlockOptions",
|
|
12
|
+
params: [client.config.contentId, articleId]
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
// src/core/actions/watchUnlockStatus.ts
|
|
17
|
+
function watchUnlockStatus(client, { articleId }, callback) {
|
|
18
|
+
return client.listenerRequest(
|
|
19
|
+
{
|
|
20
|
+
method: "frak_listenToArticleUnlockStatus",
|
|
21
|
+
params: [client.config.contentId, articleId]
|
|
22
|
+
},
|
|
23
|
+
callback
|
|
24
|
+
);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// src/core/actions/watchWalletStatus.ts
|
|
28
|
+
function watchWalletStatus(client, callback) {
|
|
29
|
+
return client.listenerRequest(
|
|
30
|
+
{
|
|
31
|
+
method: "frak_listenToWalletStatus"
|
|
32
|
+
},
|
|
33
|
+
callback
|
|
34
|
+
);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// src/core/actions/startUnlock.ts
|
|
38
|
+
async function getStartArticleUnlockUrl(config, params) {
|
|
39
|
+
const { compressed, compressedHash } = await hashAndCompressData(
|
|
40
|
+
{
|
|
41
|
+
method: "frak_startArticleUnlock",
|
|
42
|
+
params: {
|
|
43
|
+
...params,
|
|
44
|
+
contentId: config.contentId,
|
|
45
|
+
contentTitle: config.contentTitle
|
|
46
|
+
}
|
|
47
|
+
},
|
|
48
|
+
redirectRequestKeyProvider
|
|
49
|
+
);
|
|
50
|
+
const outputUrl = new URL(config.walletUrl);
|
|
51
|
+
outputUrl.pathname = "/paywall";
|
|
52
|
+
outputUrl.searchParams.set("params", encodeURIComponent(compressed));
|
|
53
|
+
outputUrl.searchParams.set("hash", encodeURIComponent(compressedHash));
|
|
54
|
+
return outputUrl.toString();
|
|
55
|
+
}
|
|
56
|
+
async function decodeStartUnlockReturn({
|
|
57
|
+
result,
|
|
58
|
+
hash
|
|
59
|
+
}) {
|
|
60
|
+
const keyProvider = getRedirectResponseResponseKeyProvider(
|
|
61
|
+
"frak_startArticleUnlock"
|
|
62
|
+
);
|
|
63
|
+
return decompressDataAndCheckHash(
|
|
64
|
+
{
|
|
65
|
+
compressed: decodeURIComponent(result),
|
|
66
|
+
compressedHash: decodeURIComponent(hash)
|
|
67
|
+
},
|
|
68
|
+
keyProvider
|
|
69
|
+
);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export {
|
|
73
|
+
getArticleUnlockOptions,
|
|
74
|
+
watchUnlockStatus,
|
|
75
|
+
watchWalletStatus,
|
|
76
|
+
getStartArticleUnlockUrl,
|
|
77
|
+
decodeStartUnlockReturn
|
|
78
|
+
};
|
|
@@ -0,0 +1,171 @@
|
|
|
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
|
+
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
var _chunk2XUJYDD3cjs = require('./chunk-2XUJYDD3.cjs');
|
|
8
|
+
|
|
9
|
+
// src/core/utils/Deferred.ts
|
|
10
|
+
var Deferred = class {
|
|
11
|
+
constructor() {
|
|
12
|
+
_chunk2XUJYDD3cjs.__publicField.call(void 0, this, "_promise");
|
|
13
|
+
_chunk2XUJYDD3cjs.__publicField.call(void 0, this, "_resolve");
|
|
14
|
+
_chunk2XUJYDD3cjs.__publicField.call(void 0, this, "_reject");
|
|
15
|
+
_chunk2XUJYDD3cjs.__publicField.call(void 0, this, "resolve", (value) => {
|
|
16
|
+
_optionalChain([this, 'access', _ => _._resolve, 'optionalCall', _2 => _2(value)]);
|
|
17
|
+
});
|
|
18
|
+
_chunk2XUJYDD3cjs.__publicField.call(void 0, this, "reject", (reason) => {
|
|
19
|
+
_optionalChain([this, 'access', _3 => _3._reject, 'optionalCall', _4 => _4(reason)]);
|
|
20
|
+
});
|
|
21
|
+
this._promise = new Promise((resolve, reject) => {
|
|
22
|
+
this._resolve = resolve;
|
|
23
|
+
this._reject = reject;
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
get promise() {
|
|
27
|
+
return this._promise;
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
// src/core/clients/transports/iframeChannelManager.ts
|
|
32
|
+
function createIFrameChannelManager() {
|
|
33
|
+
const channels = /* @__PURE__ */ new Map();
|
|
34
|
+
return {
|
|
35
|
+
// TODO: Better id system?? uid stuff?
|
|
36
|
+
createChannel: (resolver) => {
|
|
37
|
+
const id = Math.random().toString(36).substring(7);
|
|
38
|
+
channels.set(id, resolver);
|
|
39
|
+
return id;
|
|
40
|
+
},
|
|
41
|
+
getRpcResolver: (id) => channels.get(id),
|
|
42
|
+
removeChannel: (id) => channels.delete(id),
|
|
43
|
+
destroy: () => channels.clear()
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// src/core/clients/transports/iframeMessageHandler.ts
|
|
48
|
+
function createIFrameMessageHandler({
|
|
49
|
+
nexusWalletUrl,
|
|
50
|
+
iframe,
|
|
51
|
+
channelManager
|
|
52
|
+
}) {
|
|
53
|
+
if (typeof window === "undefined") {
|
|
54
|
+
throw new Error("iframe client should be used in the browser");
|
|
55
|
+
}
|
|
56
|
+
if (!iframe.contentWindow) {
|
|
57
|
+
throw new Error("The iframe does not have a content window");
|
|
58
|
+
}
|
|
59
|
+
const contentWindow = iframe.contentWindow;
|
|
60
|
+
const isConnected = new Deferred();
|
|
61
|
+
const msgHandler = async (event) => {
|
|
62
|
+
if (!event.origin) {
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
if (new URL(event.origin).origin.toLowerCase() !== new URL(nexusWalletUrl).origin.toLowerCase()) {
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
if ("lifecycle" in event.data) {
|
|
69
|
+
isConnected.resolve(event.data.lifecycle === "connected");
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
const channel = event.data.id;
|
|
73
|
+
const resolver = channelManager.getRpcResolver(channel);
|
|
74
|
+
if (!resolver) {
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
await resolver(event.data);
|
|
78
|
+
};
|
|
79
|
+
window.addEventListener("message", msgHandler);
|
|
80
|
+
const sendEvent = (message) => {
|
|
81
|
+
contentWindow.postMessage(message, {
|
|
82
|
+
targetOrigin: nexusWalletUrl
|
|
83
|
+
});
|
|
84
|
+
};
|
|
85
|
+
const cleanup = () => {
|
|
86
|
+
window.removeEventListener("message", msgHandler);
|
|
87
|
+
};
|
|
88
|
+
return {
|
|
89
|
+
isConnected: isConnected.promise,
|
|
90
|
+
sendEvent,
|
|
91
|
+
cleanup
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
// src/core/clients/createIFrameNexusClient.ts
|
|
96
|
+
function createIFrameNexusClient({
|
|
97
|
+
config,
|
|
98
|
+
iframe
|
|
99
|
+
}) {
|
|
100
|
+
const channelManager = createIFrameChannelManager();
|
|
101
|
+
const messageHandler = createIFrameMessageHandler({
|
|
102
|
+
nexusWalletUrl: config.walletUrl,
|
|
103
|
+
iframe,
|
|
104
|
+
channelManager
|
|
105
|
+
});
|
|
106
|
+
const request = async (args) => {
|
|
107
|
+
const isConnected = await messageHandler.isConnected;
|
|
108
|
+
if (!isConnected) {
|
|
109
|
+
throw new Error("The iframe provider isn't connected yet");
|
|
110
|
+
}
|
|
111
|
+
const result = new Deferred();
|
|
112
|
+
const resultCompressionKeyProvider = _chunk2XUJYDD3cjs.getIFrameResponseKeyProvider.call(void 0, args);
|
|
113
|
+
const channelId = channelManager.createChannel(async (message) => {
|
|
114
|
+
const decompressed = await _chunk2XUJYDD3cjs.decompressDataAndCheckHash.call(void 0,
|
|
115
|
+
message.data,
|
|
116
|
+
resultCompressionKeyProvider
|
|
117
|
+
);
|
|
118
|
+
result.resolve(decompressed);
|
|
119
|
+
channelManager.removeChannel(channelId);
|
|
120
|
+
});
|
|
121
|
+
const compressedMessage = await _chunk2XUJYDD3cjs.hashAndCompressData.call(void 0,
|
|
122
|
+
args,
|
|
123
|
+
_chunk2XUJYDD3cjs.iFrameRequestKeyProvider
|
|
124
|
+
);
|
|
125
|
+
messageHandler.sendEvent({
|
|
126
|
+
id: channelId,
|
|
127
|
+
topic: args.method,
|
|
128
|
+
data: compressedMessage
|
|
129
|
+
});
|
|
130
|
+
return result.promise;
|
|
131
|
+
};
|
|
132
|
+
const listenerRequest = async (args, callback) => {
|
|
133
|
+
const isConnected = await messageHandler.isConnected;
|
|
134
|
+
if (!isConnected) {
|
|
135
|
+
throw new Error("The iframe provider isn't connected yet");
|
|
136
|
+
}
|
|
137
|
+
const resultCompressionKeyProvider = _chunk2XUJYDD3cjs.getIFrameResponseKeyProvider.call(void 0, args);
|
|
138
|
+
const channelId = channelManager.createChannel(async (message) => {
|
|
139
|
+
const decompressed = await _chunk2XUJYDD3cjs.decompressDataAndCheckHash.call(void 0,
|
|
140
|
+
message.data,
|
|
141
|
+
resultCompressionKeyProvider
|
|
142
|
+
);
|
|
143
|
+
callback(decompressed);
|
|
144
|
+
});
|
|
145
|
+
const compressedMessage = await _chunk2XUJYDD3cjs.hashAndCompressData.call(void 0,
|
|
146
|
+
args,
|
|
147
|
+
_chunk2XUJYDD3cjs.iFrameRequestKeyProvider
|
|
148
|
+
);
|
|
149
|
+
messageHandler.sendEvent({
|
|
150
|
+
id: channelId,
|
|
151
|
+
topic: args.method,
|
|
152
|
+
data: compressedMessage
|
|
153
|
+
});
|
|
154
|
+
};
|
|
155
|
+
const destroy = async () => {
|
|
156
|
+
channelManager.destroy();
|
|
157
|
+
messageHandler.cleanup();
|
|
158
|
+
iframe.remove();
|
|
159
|
+
};
|
|
160
|
+
return {
|
|
161
|
+
config,
|
|
162
|
+
waitForConnection: messageHandler.isConnected,
|
|
163
|
+
request,
|
|
164
|
+
listenerRequest,
|
|
165
|
+
destroy
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
|
|
170
|
+
|
|
171
|
+
exports.createIFrameNexusClient = createIFrameNexusClient;
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
import {
|
|
2
|
+
__publicField,
|
|
3
|
+
decompressDataAndCheckHash,
|
|
4
|
+
getIFrameResponseKeyProvider,
|
|
5
|
+
hashAndCompressData,
|
|
6
|
+
iFrameRequestKeyProvider
|
|
7
|
+
} from "./chunk-5QWG35A2.js";
|
|
8
|
+
|
|
9
|
+
// src/core/utils/Deferred.ts
|
|
10
|
+
var Deferred = class {
|
|
11
|
+
constructor() {
|
|
12
|
+
__publicField(this, "_promise");
|
|
13
|
+
__publicField(this, "_resolve");
|
|
14
|
+
__publicField(this, "_reject");
|
|
15
|
+
__publicField(this, "resolve", (value) => {
|
|
16
|
+
this._resolve?.(value);
|
|
17
|
+
});
|
|
18
|
+
__publicField(this, "reject", (reason) => {
|
|
19
|
+
this._reject?.(reason);
|
|
20
|
+
});
|
|
21
|
+
this._promise = new Promise((resolve, reject) => {
|
|
22
|
+
this._resolve = resolve;
|
|
23
|
+
this._reject = reject;
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
get promise() {
|
|
27
|
+
return this._promise;
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
// src/core/clients/transports/iframeChannelManager.ts
|
|
32
|
+
function createIFrameChannelManager() {
|
|
33
|
+
const channels = /* @__PURE__ */ new Map();
|
|
34
|
+
return {
|
|
35
|
+
// TODO: Better id system?? uid stuff?
|
|
36
|
+
createChannel: (resolver) => {
|
|
37
|
+
const id = Math.random().toString(36).substring(7);
|
|
38
|
+
channels.set(id, resolver);
|
|
39
|
+
return id;
|
|
40
|
+
},
|
|
41
|
+
getRpcResolver: (id) => channels.get(id),
|
|
42
|
+
removeChannel: (id) => channels.delete(id),
|
|
43
|
+
destroy: () => channels.clear()
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// src/core/clients/transports/iframeMessageHandler.ts
|
|
48
|
+
function createIFrameMessageHandler({
|
|
49
|
+
nexusWalletUrl,
|
|
50
|
+
iframe,
|
|
51
|
+
channelManager
|
|
52
|
+
}) {
|
|
53
|
+
if (typeof window === "undefined") {
|
|
54
|
+
throw new Error("iframe client should be used in the browser");
|
|
55
|
+
}
|
|
56
|
+
if (!iframe.contentWindow) {
|
|
57
|
+
throw new Error("The iframe does not have a content window");
|
|
58
|
+
}
|
|
59
|
+
const contentWindow = iframe.contentWindow;
|
|
60
|
+
const isConnected = new Deferred();
|
|
61
|
+
const msgHandler = async (event) => {
|
|
62
|
+
if (!event.origin) {
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
if (new URL(event.origin).origin.toLowerCase() !== new URL(nexusWalletUrl).origin.toLowerCase()) {
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
if ("lifecycle" in event.data) {
|
|
69
|
+
isConnected.resolve(event.data.lifecycle === "connected");
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
const channel = event.data.id;
|
|
73
|
+
const resolver = channelManager.getRpcResolver(channel);
|
|
74
|
+
if (!resolver) {
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
await resolver(event.data);
|
|
78
|
+
};
|
|
79
|
+
window.addEventListener("message", msgHandler);
|
|
80
|
+
const sendEvent = (message) => {
|
|
81
|
+
contentWindow.postMessage(message, {
|
|
82
|
+
targetOrigin: nexusWalletUrl
|
|
83
|
+
});
|
|
84
|
+
};
|
|
85
|
+
const cleanup = () => {
|
|
86
|
+
window.removeEventListener("message", msgHandler);
|
|
87
|
+
};
|
|
88
|
+
return {
|
|
89
|
+
isConnected: isConnected.promise,
|
|
90
|
+
sendEvent,
|
|
91
|
+
cleanup
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
// src/core/clients/createIFrameNexusClient.ts
|
|
96
|
+
function createIFrameNexusClient({
|
|
97
|
+
config,
|
|
98
|
+
iframe
|
|
99
|
+
}) {
|
|
100
|
+
const channelManager = createIFrameChannelManager();
|
|
101
|
+
const messageHandler = createIFrameMessageHandler({
|
|
102
|
+
nexusWalletUrl: config.walletUrl,
|
|
103
|
+
iframe,
|
|
104
|
+
channelManager
|
|
105
|
+
});
|
|
106
|
+
const request = async (args) => {
|
|
107
|
+
const isConnected = await messageHandler.isConnected;
|
|
108
|
+
if (!isConnected) {
|
|
109
|
+
throw new Error("The iframe provider isn't connected yet");
|
|
110
|
+
}
|
|
111
|
+
const result = new Deferred();
|
|
112
|
+
const resultCompressionKeyProvider = getIFrameResponseKeyProvider(args);
|
|
113
|
+
const channelId = channelManager.createChannel(async (message) => {
|
|
114
|
+
const decompressed = await decompressDataAndCheckHash(
|
|
115
|
+
message.data,
|
|
116
|
+
resultCompressionKeyProvider
|
|
117
|
+
);
|
|
118
|
+
result.resolve(decompressed);
|
|
119
|
+
channelManager.removeChannel(channelId);
|
|
120
|
+
});
|
|
121
|
+
const compressedMessage = await hashAndCompressData(
|
|
122
|
+
args,
|
|
123
|
+
iFrameRequestKeyProvider
|
|
124
|
+
);
|
|
125
|
+
messageHandler.sendEvent({
|
|
126
|
+
id: channelId,
|
|
127
|
+
topic: args.method,
|
|
128
|
+
data: compressedMessage
|
|
129
|
+
});
|
|
130
|
+
return result.promise;
|
|
131
|
+
};
|
|
132
|
+
const listenerRequest = async (args, callback) => {
|
|
133
|
+
const isConnected = await messageHandler.isConnected;
|
|
134
|
+
if (!isConnected) {
|
|
135
|
+
throw new Error("The iframe provider isn't connected yet");
|
|
136
|
+
}
|
|
137
|
+
const resultCompressionKeyProvider = getIFrameResponseKeyProvider(args);
|
|
138
|
+
const channelId = channelManager.createChannel(async (message) => {
|
|
139
|
+
const decompressed = await decompressDataAndCheckHash(
|
|
140
|
+
message.data,
|
|
141
|
+
resultCompressionKeyProvider
|
|
142
|
+
);
|
|
143
|
+
callback(decompressed);
|
|
144
|
+
});
|
|
145
|
+
const compressedMessage = await hashAndCompressData(
|
|
146
|
+
args,
|
|
147
|
+
iFrameRequestKeyProvider
|
|
148
|
+
);
|
|
149
|
+
messageHandler.sendEvent({
|
|
150
|
+
id: channelId,
|
|
151
|
+
topic: args.method,
|
|
152
|
+
data: compressedMessage
|
|
153
|
+
});
|
|
154
|
+
};
|
|
155
|
+
const destroy = async () => {
|
|
156
|
+
channelManager.destroy();
|
|
157
|
+
messageHandler.cleanup();
|
|
158
|
+
iframe.remove();
|
|
159
|
+
};
|
|
160
|
+
return {
|
|
161
|
+
config,
|
|
162
|
+
waitForConnection: messageHandler.isConnected,
|
|
163
|
+
request,
|
|
164
|
+
listenerRequest,
|
|
165
|
+
destroy
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
export {
|
|
170
|
+
createIFrameNexusClient
|
|
171
|
+
};
|
|
@@ -2,7 +2,7 @@ import { Hex, Address, RpcSchema } from 'viem';
|
|
|
2
2
|
import { Prettify } from 'viem/chains';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
|
-
* Configuration for the
|
|
5
|
+
* Configuration for the Nexus Wallet SDK
|
|
6
6
|
*/
|
|
7
7
|
type NexusWalletSdkConfig = Readonly<{
|
|
8
8
|
walletUrl: string;
|
|
@@ -29,6 +29,7 @@ type StartArticleUnlockParams = Readonly<{
|
|
|
29
29
|
articleUrl: string;
|
|
30
30
|
redirectUrl: string;
|
|
31
31
|
previewUrl?: string;
|
|
32
|
+
provider: "le-monde" | "wired" | "l-equipe";
|
|
32
33
|
}>;
|
|
33
34
|
/**
|
|
34
35
|
* Return type of the unlock request
|
|
@@ -69,7 +70,7 @@ type UnlockOptionsReturnType = Readonly<{
|
|
|
69
70
|
*/
|
|
70
71
|
type ArticleUnlockStatusReturnType = Readonly<UnlockStatusLocked | UnlockStatusProcessing | UnlockStatusValid | UnlockStatusError>;
|
|
71
72
|
/**
|
|
72
|
-
* When the content unlocked was expired
|
|
73
|
+
* When the content unlocked was expired or not unlocked
|
|
73
74
|
*/
|
|
74
75
|
type UnlockStatusLocked = {
|
|
75
76
|
key: "expired";
|
|
@@ -80,9 +81,11 @@ type UnlockStatusLocked = {
|
|
|
80
81
|
status: "locked";
|
|
81
82
|
};
|
|
82
83
|
/**
|
|
83
|
-
* When the content
|
|
84
|
+
* When the content unlock is in progress
|
|
84
85
|
*/
|
|
85
86
|
type UnlockStatusProcessing = {
|
|
87
|
+
status: "in-progress";
|
|
88
|
+
} & ({
|
|
86
89
|
key: "preparing" | "waiting-user-validation";
|
|
87
90
|
} | {
|
|
88
91
|
key: "waiting-transaction-bundling";
|
|
@@ -91,9 +94,9 @@ type UnlockStatusProcessing = {
|
|
|
91
94
|
key: "waiting-transaction-confirmation";
|
|
92
95
|
userOpHash: Hex;
|
|
93
96
|
txHash: Hex;
|
|
94
|
-
};
|
|
97
|
+
});
|
|
95
98
|
/**
|
|
96
|
-
* When the content unlocked
|
|
99
|
+
* When the content is unlocked
|
|
97
100
|
*/
|
|
98
101
|
type UnlockStatusValid = {
|
|
99
102
|
key: "valid";
|
|
@@ -101,7 +104,7 @@ type UnlockStatusValid = {
|
|
|
101
104
|
allowedUntil: number;
|
|
102
105
|
};
|
|
103
106
|
/**
|
|
104
|
-
* When the content
|
|
107
|
+
* When the unlock content is in error
|
|
105
108
|
*/
|
|
106
109
|
type UnlockStatusError = {
|
|
107
110
|
key: "error";
|
|
@@ -237,7 +240,7 @@ type IFrameLifecycleEvent = {
|
|
|
237
240
|
};
|
|
238
241
|
|
|
239
242
|
/**
|
|
240
|
-
* Representing a
|
|
243
|
+
* Representing a Nexus client
|
|
241
244
|
*/
|
|
242
245
|
type NexusClient = {
|
|
243
246
|
config: NexusWalletSdkConfig;
|
|
@@ -2,7 +2,7 @@ import { Hex, Address, RpcSchema } from 'viem';
|
|
|
2
2
|
import { Prettify } from 'viem/chains';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
|
-
* Configuration for the
|
|
5
|
+
* Configuration for the Nexus Wallet SDK
|
|
6
6
|
*/
|
|
7
7
|
type NexusWalletSdkConfig = Readonly<{
|
|
8
8
|
walletUrl: string;
|
|
@@ -29,6 +29,7 @@ type StartArticleUnlockParams = Readonly<{
|
|
|
29
29
|
articleUrl: string;
|
|
30
30
|
redirectUrl: string;
|
|
31
31
|
previewUrl?: string;
|
|
32
|
+
provider: "le-monde" | "wired" | "l-equipe";
|
|
32
33
|
}>;
|
|
33
34
|
/**
|
|
34
35
|
* Return type of the unlock request
|
|
@@ -69,7 +70,7 @@ type UnlockOptionsReturnType = Readonly<{
|
|
|
69
70
|
*/
|
|
70
71
|
type ArticleUnlockStatusReturnType = Readonly<UnlockStatusLocked | UnlockStatusProcessing | UnlockStatusValid | UnlockStatusError>;
|
|
71
72
|
/**
|
|
72
|
-
* When the content unlocked was expired
|
|
73
|
+
* When the content unlocked was expired or not unlocked
|
|
73
74
|
*/
|
|
74
75
|
type UnlockStatusLocked = {
|
|
75
76
|
key: "expired";
|
|
@@ -80,9 +81,11 @@ type UnlockStatusLocked = {
|
|
|
80
81
|
status: "locked";
|
|
81
82
|
};
|
|
82
83
|
/**
|
|
83
|
-
* When the content
|
|
84
|
+
* When the content unlock is in progress
|
|
84
85
|
*/
|
|
85
86
|
type UnlockStatusProcessing = {
|
|
87
|
+
status: "in-progress";
|
|
88
|
+
} & ({
|
|
86
89
|
key: "preparing" | "waiting-user-validation";
|
|
87
90
|
} | {
|
|
88
91
|
key: "waiting-transaction-bundling";
|
|
@@ -91,9 +94,9 @@ type UnlockStatusProcessing = {
|
|
|
91
94
|
key: "waiting-transaction-confirmation";
|
|
92
95
|
userOpHash: Hex;
|
|
93
96
|
txHash: Hex;
|
|
94
|
-
};
|
|
97
|
+
});
|
|
95
98
|
/**
|
|
96
|
-
* When the content unlocked
|
|
99
|
+
* When the content is unlocked
|
|
97
100
|
*/
|
|
98
101
|
type UnlockStatusValid = {
|
|
99
102
|
key: "valid";
|
|
@@ -101,7 +104,7 @@ type UnlockStatusValid = {
|
|
|
101
104
|
allowedUntil: number;
|
|
102
105
|
};
|
|
103
106
|
/**
|
|
104
|
-
* When the content
|
|
107
|
+
* When the unlock content is in error
|
|
105
108
|
*/
|
|
106
109
|
type UnlockStatusError = {
|
|
107
110
|
key: "error";
|
|
@@ -237,7 +240,7 @@ type IFrameLifecycleEvent = {
|
|
|
237
240
|
};
|
|
238
241
|
|
|
239
242
|
/**
|
|
240
|
-
* Representing a
|
|
243
|
+
* Representing a Nexus client
|
|
241
244
|
*/
|
|
242
245
|
type NexusClient = {
|
|
243
246
|
config: NexusWalletSdkConfig;
|