@frak-labs/nexus-sdk 0.0.9 → 0.0.11
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-5CFD5FM2.js +86 -0
- package/dist/chunk-7MVQQ2X6.js +381 -0
- package/dist/chunk-ETV4XYOV.cjs +7 -0
- package/dist/chunk-GUDT2W6I.js +70 -0
- package/dist/chunk-IQQTTKJL.cjs +70 -0
- package/dist/chunk-PKBMQBKP.js +7 -0
- package/dist/chunk-S5FVCA2E.cjs +86 -0
- package/dist/chunk-V3S6RBRJ.cjs +381 -0
- package/dist/client-C7u9zGwC.d.cts +332 -0
- package/dist/client-gE3fYzkD.d.ts +332 -0
- package/dist/core/actions/index.cjs +3 -3
- package/dist/core/actions/index.d.cts +21 -28
- package/dist/core/actions/index.d.ts +21 -28
- package/dist/core/actions/index.js +12 -12
- package/dist/core/index.cjs +3 -8
- package/dist/core/index.d.cts +8 -35
- package/dist/core/index.d.ts +8 -35
- package/dist/core/index.js +9 -14
- package/dist/core/interactions/index.cjs +13 -0
- package/dist/core/interactions/index.d.cts +53 -0
- package/dist/core/interactions/index.d.ts +53 -0
- package/dist/core/interactions/index.js +13 -0
- package/dist/error-C4Zm5nQe.d.cts +27 -0
- package/dist/error-C4Zm5nQe.d.ts +27 -0
- package/dist/interaction-D3-M3nBh.d.cts +22 -0
- package/dist/interaction-D3-M3nBh.d.ts +22 -0
- package/dist/react/index.cjs +279 -166
- package/dist/react/index.d.cts +80 -37
- package/dist/react/index.d.ts +80 -37
- package/dist/react/index.js +291 -178
- package/dist/sendTransaction-BZW627cT.d.cts +30 -0
- package/dist/sendTransaction-DpJTfGJc.d.ts +30 -0
- package/package.json +16 -7
- package/dist/chunk-AYZHGMEV.cjs +0 -171
- package/dist/chunk-PDR3CF3P.js +0 -86
- package/dist/chunk-SZUN32YC.js +0 -171
- package/dist/chunk-VK7GPKK4.js +0 -169
- package/dist/chunk-X4JNNWJ4.cjs +0 -86
- package/dist/chunk-ZOLP2FJZ.cjs +0 -169
- package/dist/client-BwzXSgqQ.d.cts +0 -278
- package/dist/client-BwzXSgqQ.d.ts +0 -278
- package/dist/watchUnlockStatus-DXClCYH9.d.cts +0 -43
- package/dist/watchUnlockStatus-WJxoDliF.d.ts +0 -43
package/dist/chunk-X4JNNWJ4.cjs
DELETED
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
var _chunkZOLP2FJZcjs = require('./chunk-ZOLP2FJZ.cjs');
|
|
7
|
-
|
|
8
|
-
// src/core/actions/getUnlockOptions.ts
|
|
9
|
-
function getArticleUnlockOptions(client, { articleId, contentId }) {
|
|
10
|
-
return client.request({
|
|
11
|
-
method: "frak_getArticleUnlockOptions",
|
|
12
|
-
params: [contentId, articleId]
|
|
13
|
-
});
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
// src/core/actions/watchUnlockStatus.ts
|
|
17
|
-
function watchUnlockStatus(client, { articleId, contentId }, callback) {
|
|
18
|
-
return client.listenerRequest(
|
|
19
|
-
{
|
|
20
|
-
method: "frak_listenToArticleUnlockStatus",
|
|
21
|
-
params: [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 _chunkZOLP2FJZcjs.hashAndCompressData.call(void 0,
|
|
40
|
-
{
|
|
41
|
-
method: "frak_startArticleUnlock",
|
|
42
|
-
params
|
|
43
|
-
},
|
|
44
|
-
_chunkZOLP2FJZcjs.redirectRequestKeyProvider
|
|
45
|
-
);
|
|
46
|
-
const outputUrl = new URL(config.walletUrl);
|
|
47
|
-
outputUrl.pathname = "/paywall";
|
|
48
|
-
outputUrl.searchParams.set("params", encodeURIComponent(compressed));
|
|
49
|
-
outputUrl.searchParams.set("hash", encodeURIComponent(compressedHash));
|
|
50
|
-
return outputUrl.toString();
|
|
51
|
-
}
|
|
52
|
-
async function decodeStartUnlockReturn({
|
|
53
|
-
result,
|
|
54
|
-
hash
|
|
55
|
-
}) {
|
|
56
|
-
const keyProvider = _chunkZOLP2FJZcjs.getRedirectResponseResponseKeyProvider.call(void 0,
|
|
57
|
-
"frak_startArticleUnlock"
|
|
58
|
-
);
|
|
59
|
-
return _chunkZOLP2FJZcjs.decompressDataAndCheckHash.call(void 0,
|
|
60
|
-
{
|
|
61
|
-
compressed: decodeURIComponent(result),
|
|
62
|
-
compressedHash: decodeURIComponent(hash)
|
|
63
|
-
},
|
|
64
|
-
keyProvider
|
|
65
|
-
);
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
// src/core/actions/setUserReferred.ts
|
|
69
|
-
function setUserReferred(client, { contentId, walletAddress }, callback) {
|
|
70
|
-
return client.listenerRequest(
|
|
71
|
-
{
|
|
72
|
-
method: "frak_listenToSetUserReferred",
|
|
73
|
-
params: [contentId, walletAddress]
|
|
74
|
-
},
|
|
75
|
-
callback
|
|
76
|
-
);
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
exports.getArticleUnlockOptions = getArticleUnlockOptions; exports.watchUnlockStatus = watchUnlockStatus; exports.watchWalletStatus = watchWalletStatus; exports.getStartArticleUnlockUrl = getStartArticleUnlockUrl; exports.decodeStartUnlockReturn = decodeStartUnlockReturn; exports.setUserReferred = setUserReferred;
|
package/dist/chunk-ZOLP2FJZ.cjs
DELETED
|
@@ -1,169 +0,0 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } 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; }var __defProp = Object.defineProperty;
|
|
2
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
3
|
-
var __publicField = (obj, key, value) => {
|
|
4
|
-
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
5
|
-
return value;
|
|
6
|
-
};
|
|
7
|
-
|
|
8
|
-
// src/core/utils/compression/compress.ts
|
|
9
|
-
var _asynclzstring = require('async-lz-string');
|
|
10
|
-
var _jssha256 = require('js-sha256');
|
|
11
|
-
async function hashAndCompressData(data, keyProvider) {
|
|
12
|
-
const keys = keyProvider(data);
|
|
13
|
-
const validationHash = _jssha256.sha256.call(void 0, keys.join("_"));
|
|
14
|
-
const hashProtectedData = {
|
|
15
|
-
...data,
|
|
16
|
-
validationHash
|
|
17
|
-
};
|
|
18
|
-
const compressed = await compressJson(hashProtectedData);
|
|
19
|
-
const compressedHash = _jssha256.sha256.call(void 0, compressed);
|
|
20
|
-
return {
|
|
21
|
-
compressed,
|
|
22
|
-
compressedHash
|
|
23
|
-
};
|
|
24
|
-
}
|
|
25
|
-
async function compressJson(data) {
|
|
26
|
-
return _asynclzstring.compressToBase64.call(void 0, JSON.stringify(data));
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
// src/core/utils/compression/decompress.ts
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
async function decompressDataAndCheckHash(compressedData, keyAccessor) {
|
|
33
|
-
if (!(_optionalChain([compressedData, 'optionalAccess', _ => _.compressed]) && _optionalChain([compressedData, 'optionalAccess', _2 => _2.compressedHash]))) {
|
|
34
|
-
throw new Error("Missing compressed data");
|
|
35
|
-
}
|
|
36
|
-
const parsedData = await decompressJson(
|
|
37
|
-
compressedData.compressed
|
|
38
|
-
);
|
|
39
|
-
if (!parsedData) {
|
|
40
|
-
throw new Error(`Invalid compressed data: ${parsedData}`);
|
|
41
|
-
}
|
|
42
|
-
if (!_optionalChain([parsedData, 'optionalAccess', _3 => _3.validationHash])) {
|
|
43
|
-
throw new Error("Missing validation hash");
|
|
44
|
-
}
|
|
45
|
-
const expectedCompressedHash = _jssha256.sha256.call(void 0, compressedData.compressed);
|
|
46
|
-
if (expectedCompressedHash !== compressedData.compressedHash) {
|
|
47
|
-
throw new Error("Invalid compressed hash");
|
|
48
|
-
}
|
|
49
|
-
const keys = keyAccessor(parsedData);
|
|
50
|
-
const expectedValidationHash = _jssha256.sha256.call(void 0, keys.join("_"));
|
|
51
|
-
if (expectedValidationHash !== parsedData.validationHash) {
|
|
52
|
-
throw new Error("Invalid data validation hash");
|
|
53
|
-
}
|
|
54
|
-
return parsedData;
|
|
55
|
-
}
|
|
56
|
-
async function decompressJson(data) {
|
|
57
|
-
const decompressed = await _asynclzstring.decompressFromBase64.call(void 0, data);
|
|
58
|
-
try {
|
|
59
|
-
return JSON.parse(decompressed);
|
|
60
|
-
} catch (e) {
|
|
61
|
-
console.error("Invalid compressed data", e);
|
|
62
|
-
return null;
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
// src/core/utils/compression/iframeRpcKeyProvider.ts
|
|
67
|
-
var iFrameRequestKeyProvider = (args) => {
|
|
68
|
-
if (args.method === "frak_getArticleUnlockOptions") {
|
|
69
|
-
return ["get-price", args.params[0], args.params[1]];
|
|
70
|
-
}
|
|
71
|
-
if (args.method === "frak_listenToWalletStatus") {
|
|
72
|
-
return ["wallet-status"];
|
|
73
|
-
}
|
|
74
|
-
if (args.method === "frak_listenToArticleUnlockStatus") {
|
|
75
|
-
return ["article-unlock-status", args.params[0], args.params[1]];
|
|
76
|
-
}
|
|
77
|
-
if (args.method === "frak_listenToSetUserReferred") {
|
|
78
|
-
return ["user-referred", args.params[0], args.params[1]];
|
|
79
|
-
}
|
|
80
|
-
throw new Error(`No key provider found for the arguments ${args}`);
|
|
81
|
-
};
|
|
82
|
-
function getIFrameResponseKeyProvider(param) {
|
|
83
|
-
if (param.method === "frak_getArticleUnlockOptions") {
|
|
84
|
-
return (response) => [
|
|
85
|
-
"get-price-response",
|
|
86
|
-
response.prices.length
|
|
87
|
-
];
|
|
88
|
-
}
|
|
89
|
-
if (param.method === "frak_listenToWalletStatus") {
|
|
90
|
-
return (response) => [
|
|
91
|
-
"wallet-status",
|
|
92
|
-
response.key,
|
|
93
|
-
response.key === "connected" ? response.wallet : "0xdeadbeef"
|
|
94
|
-
];
|
|
95
|
-
}
|
|
96
|
-
if (param.method === "frak_listenToArticleUnlockStatus") {
|
|
97
|
-
return (response) => [
|
|
98
|
-
"article-unlock-status",
|
|
99
|
-
response.key,
|
|
100
|
-
response.key === "valid" ? response.allowedUntil.toString(16) : "deadbeef"
|
|
101
|
-
];
|
|
102
|
-
}
|
|
103
|
-
if (param.method === "frak_listenToSetUserReferred") {
|
|
104
|
-
return (response) => [
|
|
105
|
-
"user-referred",
|
|
106
|
-
response.key
|
|
107
|
-
];
|
|
108
|
-
}
|
|
109
|
-
throw new Error(`No key provider found for the request ${param}`);
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
// src/core/utils/iframeHelper.ts
|
|
113
|
-
function createIframe({
|
|
114
|
-
walletBaseUrl
|
|
115
|
-
}) {
|
|
116
|
-
const alreadyCreatedIFrame = document.querySelector("#nexus-wallet");
|
|
117
|
-
if (alreadyCreatedIFrame) {
|
|
118
|
-
return Promise.resolve(void 0);
|
|
119
|
-
}
|
|
120
|
-
const iframe = document.createElement("iframe");
|
|
121
|
-
iframe.name = "nexus-wallet";
|
|
122
|
-
iframe.id = "nexus-wallet";
|
|
123
|
-
iframe.style.width = "0";
|
|
124
|
-
iframe.style.height = "0";
|
|
125
|
-
iframe.style.border = "0";
|
|
126
|
-
iframe.style.position = "absolute";
|
|
127
|
-
iframe.style.top = "-1000px";
|
|
128
|
-
iframe.style.left = "-1000px";
|
|
129
|
-
document.body.appendChild(iframe);
|
|
130
|
-
return new Promise((resolve) => {
|
|
131
|
-
_optionalChain([iframe, 'optionalAccess', _4 => _4.addEventListener, 'call', _5 => _5("load", () => resolve(iframe))]);
|
|
132
|
-
iframe.src = `${walletBaseUrl}/listener`;
|
|
133
|
-
});
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
// src/core/utils/compression/redirectKeyProvider.ts
|
|
137
|
-
var redirectRequestKeyProvider = (args) => {
|
|
138
|
-
if (args.method === "frak_startArticleUnlock") {
|
|
139
|
-
return [
|
|
140
|
-
"start-unlock",
|
|
141
|
-
args.params.contentId,
|
|
142
|
-
args.params.articleId,
|
|
143
|
-
args.params.price.index.toString()
|
|
144
|
-
];
|
|
145
|
-
}
|
|
146
|
-
throw new Error(`No key provider found for the arguments ${args}`);
|
|
147
|
-
};
|
|
148
|
-
function getRedirectResponseResponseKeyProvider(method) {
|
|
149
|
-
if (method === "frak_startArticleUnlock") {
|
|
150
|
-
return (response) => [
|
|
151
|
-
"start-unlock",
|
|
152
|
-
response.key,
|
|
153
|
-
response.status,
|
|
154
|
-
_nullishCoalesce(response.user, () => ( "0xdeadbeef"))
|
|
155
|
-
];
|
|
156
|
-
}
|
|
157
|
-
throw new Error(`No key provider found for the method ${method}`);
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
exports.__publicField = __publicField; exports.hashAndCompressData = hashAndCompressData; exports.decompressDataAndCheckHash = decompressDataAndCheckHash; exports.iFrameRequestKeyProvider = iFrameRequestKeyProvider; exports.getIFrameResponseKeyProvider = getIFrameResponseKeyProvider; exports.createIframe = createIframe; exports.redirectRequestKeyProvider = redirectRequestKeyProvider; exports.getRedirectResponseResponseKeyProvider = getRedirectResponseResponseKeyProvider;
|
|
@@ -1,278 +0,0 @@
|
|
|
1
|
-
import { Hex, Address, RpcSchema } from 'viem';
|
|
2
|
-
import { Prettify } from 'viem/chains';
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Configuration for the Nexus Wallet SDK
|
|
6
|
-
*/
|
|
7
|
-
type NexusWalletSdkConfig = Readonly<{
|
|
8
|
-
walletUrl: string;
|
|
9
|
-
metadata: {
|
|
10
|
-
name: string;
|
|
11
|
-
};
|
|
12
|
-
}>;
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* Parameters of the referred request
|
|
16
|
-
*/
|
|
17
|
-
type SetUserReferredParams = Readonly<{
|
|
18
|
-
contentId: Hex;
|
|
19
|
-
}>;
|
|
20
|
-
/**
|
|
21
|
-
* Return type of the referred request
|
|
22
|
-
*/
|
|
23
|
-
type SetUserReferredReturnType = UserIsSameWallet | UserReferredSuccessful | UserReferredHistory;
|
|
24
|
-
type UserIsSameWallet = {
|
|
25
|
-
key: "same-wallet";
|
|
26
|
-
};
|
|
27
|
-
type UserReferredSuccessful = {
|
|
28
|
-
key: "referred-successful";
|
|
29
|
-
};
|
|
30
|
-
type UserReferredHistory = {
|
|
31
|
-
key: "referred-history";
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
type PaidArticleUnlockPrice = Readonly<{
|
|
35
|
-
index: number;
|
|
36
|
-
unlockDurationInSec: number;
|
|
37
|
-
frkAmount: Hex;
|
|
38
|
-
}>;
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
* Request to unlock a paid article
|
|
42
|
-
*/
|
|
43
|
-
type StartArticleUnlockParams = Readonly<{
|
|
44
|
-
articleId: Hex;
|
|
45
|
-
contentId: Hex;
|
|
46
|
-
imageUrl: string;
|
|
47
|
-
articleTitle: string;
|
|
48
|
-
contentTitle: string;
|
|
49
|
-
price: PaidArticleUnlockPrice;
|
|
50
|
-
articleUrl: string;
|
|
51
|
-
redirectUrl: string;
|
|
52
|
-
previewUrl?: string;
|
|
53
|
-
provider: "le-monde" | "wired" | "l-equipe";
|
|
54
|
-
}>;
|
|
55
|
-
/**
|
|
56
|
-
* Return type of the unlock request
|
|
57
|
-
*/
|
|
58
|
-
type StartArticleUnlockReturnType = UnlockSuccess | AlreadyUnlocked | UnlockError;
|
|
59
|
-
type UnlockSuccess = {
|
|
60
|
-
key: "success";
|
|
61
|
-
status: "in-progress";
|
|
62
|
-
user: Address;
|
|
63
|
-
userOpHash: Hex;
|
|
64
|
-
};
|
|
65
|
-
type AlreadyUnlocked = {
|
|
66
|
-
key: "already-unlocked";
|
|
67
|
-
status: "unlocked";
|
|
68
|
-
user: Address;
|
|
69
|
-
};
|
|
70
|
-
type UnlockError = {
|
|
71
|
-
key: "error" | "cancelled";
|
|
72
|
-
status: "locked";
|
|
73
|
-
user?: Address;
|
|
74
|
-
reason?: string;
|
|
75
|
-
};
|
|
76
|
-
|
|
77
|
-
/**
|
|
78
|
-
* The response to the get unlock options response
|
|
79
|
-
*/
|
|
80
|
-
type UnlockOptionsReturnType = Readonly<{
|
|
81
|
-
frkBalanceAsHex?: Hex;
|
|
82
|
-
prices: {
|
|
83
|
-
index: number;
|
|
84
|
-
unlockDurationInSec: number;
|
|
85
|
-
frkAmount: Hex;
|
|
86
|
-
isUserAccessible: boolean | null;
|
|
87
|
-
}[];
|
|
88
|
-
}>;
|
|
89
|
-
|
|
90
|
-
/**
|
|
91
|
-
* The different types of response for the current unlock status
|
|
92
|
-
*/
|
|
93
|
-
type ArticleUnlockStatusReturnType = Readonly<UnlockStatusLocked | UnlockStatusProcessing | UnlockStatusValid | UnlockStatusError>;
|
|
94
|
-
/**
|
|
95
|
-
* When the content unlocked was expired or not unlocked
|
|
96
|
-
*/
|
|
97
|
-
type UnlockStatusLocked = {
|
|
98
|
-
key: "expired";
|
|
99
|
-
status: "locked";
|
|
100
|
-
expiredAt: number;
|
|
101
|
-
} | {
|
|
102
|
-
key: "not-unlocked";
|
|
103
|
-
status: "locked";
|
|
104
|
-
};
|
|
105
|
-
/**
|
|
106
|
-
* When the content unlock is in progress
|
|
107
|
-
*/
|
|
108
|
-
type UnlockStatusProcessing = {
|
|
109
|
-
status: "in-progress";
|
|
110
|
-
} & ({
|
|
111
|
-
key: "preparing" | "waiting-user-validation";
|
|
112
|
-
} | {
|
|
113
|
-
key: "waiting-transaction-bundling";
|
|
114
|
-
userOpHash: Hex;
|
|
115
|
-
} | {
|
|
116
|
-
key: "waiting-transaction-confirmation";
|
|
117
|
-
userOpHash: Hex;
|
|
118
|
-
txHash: Hex;
|
|
119
|
-
});
|
|
120
|
-
/**
|
|
121
|
-
* When the content is unlocked
|
|
122
|
-
*/
|
|
123
|
-
type UnlockStatusValid = {
|
|
124
|
-
key: "valid";
|
|
125
|
-
status: "unlocked";
|
|
126
|
-
allowedUntil: number;
|
|
127
|
-
};
|
|
128
|
-
/**
|
|
129
|
-
* When the unlock content is in error
|
|
130
|
-
*/
|
|
131
|
-
type UnlockStatusError = {
|
|
132
|
-
key: "error";
|
|
133
|
-
status: "locked";
|
|
134
|
-
reason: string;
|
|
135
|
-
};
|
|
136
|
-
|
|
137
|
-
type WalletStatusReturnType = Readonly<WalletConnected | WalletNotConnected>;
|
|
138
|
-
type WalletConnected = {
|
|
139
|
-
key: "connected";
|
|
140
|
-
wallet: Address;
|
|
141
|
-
};
|
|
142
|
-
type WalletNotConnected = {
|
|
143
|
-
key: "not-connected";
|
|
144
|
-
};
|
|
145
|
-
|
|
146
|
-
/**
|
|
147
|
-
* RPC interface that's used for the iframe communication
|
|
148
|
-
*/
|
|
149
|
-
type IFrameRpcSchema = [
|
|
150
|
-
/**
|
|
151
|
-
* Method used to fetch an article unlock options
|
|
152
|
-
*/
|
|
153
|
-
{
|
|
154
|
-
Method: "frak_getArticleUnlockOptions";
|
|
155
|
-
Parameters: [contentId: Hex, articleId: Hex];
|
|
156
|
-
ReturnType: UnlockOptionsReturnType;
|
|
157
|
-
},
|
|
158
|
-
/**
|
|
159
|
-
* Method used to listen to the wallet status
|
|
160
|
-
*/
|
|
161
|
-
{
|
|
162
|
-
Method: "frak_listenToWalletStatus";
|
|
163
|
-
Parameters?: undefined;
|
|
164
|
-
ReturnType: WalletStatusReturnType;
|
|
165
|
-
},
|
|
166
|
-
/**
|
|
167
|
-
* Method used to listen to an article unlock status
|
|
168
|
-
*/
|
|
169
|
-
{
|
|
170
|
-
Method: "frak_listenToArticleUnlockStatus";
|
|
171
|
-
Parameters: [contentId: Hex, articleId: Hex];
|
|
172
|
-
ReturnType: ArticleUnlockStatusReturnType;
|
|
173
|
-
},
|
|
174
|
-
/**
|
|
175
|
-
* Method used to set the referred user
|
|
176
|
-
*/
|
|
177
|
-
{
|
|
178
|
-
Method: "frak_listenToSetUserReferred";
|
|
179
|
-
Parameters: [contentId: Hex, walletAddress: Address];
|
|
180
|
-
ReturnType: SetUserReferredReturnType;
|
|
181
|
-
}
|
|
182
|
-
];
|
|
183
|
-
/**
|
|
184
|
-
* RPC interface that's used for the redirection communication
|
|
185
|
-
*/
|
|
186
|
-
type RedirectRpcSchema = [
|
|
187
|
-
/**
|
|
188
|
-
* Method used to start the unlock of an article
|
|
189
|
-
*/
|
|
190
|
-
{
|
|
191
|
-
Method: "frak_startArticleUnlock";
|
|
192
|
-
Path: "/paywall";
|
|
193
|
-
Parameters: StartArticleUnlockParams;
|
|
194
|
-
ReturnType: StartArticleUnlockReturnType;
|
|
195
|
-
}
|
|
196
|
-
];
|
|
197
|
-
|
|
198
|
-
/**
|
|
199
|
-
* Type that extract the possible parameters from a RPC Schema
|
|
200
|
-
*/
|
|
201
|
-
type ExtractedParametersFromRpc<TRpcSchema extends RpcSchema | undefined = undefined> = TRpcSchema extends RpcSchema ? {
|
|
202
|
-
[K in keyof TRpcSchema]: Prettify<{
|
|
203
|
-
method: TRpcSchema[K] extends TRpcSchema[number] ? TRpcSchema[K]["Method"] : string;
|
|
204
|
-
} & (TRpcSchema[K] extends TRpcSchema[number] ? TRpcSchema[K]["Parameters"] extends undefined ? {
|
|
205
|
-
params?: never;
|
|
206
|
-
} : {
|
|
207
|
-
params: TRpcSchema[K]["Parameters"];
|
|
208
|
-
} : never)>;
|
|
209
|
-
}[number] : {
|
|
210
|
-
method: string;
|
|
211
|
-
params?: unknown;
|
|
212
|
-
};
|
|
213
|
-
/**
|
|
214
|
-
* Type that extract the possible return type from a RPC Schema
|
|
215
|
-
*/
|
|
216
|
-
type ExtractedReturnTypeFromRpc<TRpcSchema extends RpcSchema | undefined = undefined, TParameters extends ExtractedParametersFromRpc<TRpcSchema> = ExtractedParametersFromRpc<TRpcSchema>> = TRpcSchema extends RpcSchema ? ExtractedMethodFromRpc<TRpcSchema, TParameters["method"]>["ReturnType"] : unknown;
|
|
217
|
-
/**
|
|
218
|
-
* Type that extract the possible return type from a RPC Schema
|
|
219
|
-
*/
|
|
220
|
-
type ExtractedMethodFromRpc<TRpcSchema extends RpcSchema | undefined = undefined, TMethod extends ExtractedParametersFromRpc<TRpcSchema>["method"] = ExtractedParametersFromRpc<TRpcSchema>["method"]> = TRpcSchema extends RpcSchema ? Extract<TRpcSchema[number], {
|
|
221
|
-
Method: TMethod;
|
|
222
|
-
}> : unknown;
|
|
223
|
-
/**
|
|
224
|
-
* Type used for a one shot request function
|
|
225
|
-
*/
|
|
226
|
-
type RequestFn<TRpcSchema extends RpcSchema | undefined = undefined> = <TParameters extends ExtractedParametersFromRpc<TRpcSchema> = ExtractedParametersFromRpc<TRpcSchema>, _ReturnType = ExtractedReturnTypeFromRpc<TRpcSchema, TParameters>>(args: TParameters) => Promise<_ReturnType>;
|
|
227
|
-
/**
|
|
228
|
-
* Type used for a one shot request function
|
|
229
|
-
*/
|
|
230
|
-
type ListenerRequestFn<TRpcSchema extends RpcSchema | undefined = undefined> = <TParameters extends ExtractedParametersFromRpc<TRpcSchema> = ExtractedParametersFromRpc<TRpcSchema>>(args: TParameters, callback: (result: ExtractedReturnTypeFromRpc<TRpcSchema, TParameters>) => void) => Promise<void>;
|
|
231
|
-
/**
|
|
232
|
-
* IFrame transport interface
|
|
233
|
-
*/
|
|
234
|
-
type IFrameTransport = {
|
|
235
|
-
/**
|
|
236
|
-
* Wait for the connection to be established
|
|
237
|
-
*/
|
|
238
|
-
waitForConnection: Promise<boolean>;
|
|
239
|
-
/**
|
|
240
|
-
* Function used to perform a single request via the iframe transport
|
|
241
|
-
*/
|
|
242
|
-
request: RequestFn<IFrameRpcSchema>;
|
|
243
|
-
/**
|
|
244
|
-
* Function used to listen to a request response via the iframe transport
|
|
245
|
-
*/
|
|
246
|
-
listenerRequest: ListenerRequestFn<IFrameRpcSchema>;
|
|
247
|
-
/**
|
|
248
|
-
* Function used to destroy the iframe transport
|
|
249
|
-
*/
|
|
250
|
-
destroy: () => Promise<void>;
|
|
251
|
-
};
|
|
252
|
-
/**
|
|
253
|
-
* Represent an iframe event
|
|
254
|
-
*/
|
|
255
|
-
type IFrameEvent = IFrameRpcEvent | IFrameLifecycleEvent;
|
|
256
|
-
/**
|
|
257
|
-
* Represent an iframe rpc event
|
|
258
|
-
*/
|
|
259
|
-
type IFrameRpcEvent = {
|
|
260
|
-
id: string;
|
|
261
|
-
topic: ExtractedParametersFromRpc<IFrameRpcSchema>["method"];
|
|
262
|
-
data: {
|
|
263
|
-
compressed: string;
|
|
264
|
-
compressedHash: string;
|
|
265
|
-
};
|
|
266
|
-
};
|
|
267
|
-
type IFrameLifecycleEvent = {
|
|
268
|
-
lifecycle: "connected";
|
|
269
|
-
};
|
|
270
|
-
|
|
271
|
-
/**
|
|
272
|
-
* Representing a Nexus client
|
|
273
|
-
*/
|
|
274
|
-
type NexusClient = {
|
|
275
|
-
config: NexusWalletSdkConfig;
|
|
276
|
-
} & IFrameTransport;
|
|
277
|
-
|
|
278
|
-
export type { ArticleUnlockStatusReturnType as A, ExtractedParametersFromRpc as E, IFrameRpcSchema as I, NexusClient as N, PaidArticleUnlockPrice as P, RedirectRpcSchema as R, StartArticleUnlockReturnType as S, UnlockOptionsReturnType as U, WalletStatusReturnType as W, NexusWalletSdkConfig as a, StartArticleUnlockParams as b, SetUserReferredReturnType as c, ExtractedReturnTypeFromRpc as d, SetUserReferredParams as e, IFrameTransport as f, IFrameRpcEvent as g, IFrameEvent as h };
|