@frak-labs/nexus-sdk 0.0.10 → 0.0.12
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-BJ3CCN5P.cjs +424 -0
- package/dist/{chunk-72IEHEQX.js → chunk-GUDT2W6I.js} +32 -10
- package/dist/chunk-HXVDI2IY.js +424 -0
- package/dist/{chunk-NIFJZD3M.cjs → chunk-IQQTTKJL.cjs} +30 -8
- package/dist/chunk-S5FVCA2E.cjs +86 -0
- package/dist/client-B6_BIGc3.d.ts +357 -0
- package/dist/client-Oily5ph8.d.cts +357 -0
- package/dist/core/actions/index.cjs +2 -7
- package/dist/core/actions/index.d.cts +16 -35
- package/dist/core/actions/index.d.ts +16 -35
- package/dist/core/actions/index.js +5 -10
- package/dist/core/index.cjs +2 -4
- package/dist/core/index.d.cts +19 -19
- package/dist/core/index.d.ts +19 -19
- package/dist/core/index.js +2 -4
- package/dist/core/interactions/index.cjs +6 -2
- package/dist/core/interactions/index.d.cts +20 -6
- package/dist/core/interactions/index.d.ts +20 -6
- package/dist/core/interactions/index.js +7 -3
- package/dist/{interaction-D_CzyqRE.d.cts → interaction-D3-M3nBh.d.cts} +2 -2
- package/dist/{interaction-D_CzyqRE.d.ts → interaction-D3-M3nBh.d.ts} +2 -2
- package/dist/react/index.cjs +156 -158
- package/dist/react/index.d.cts +44 -51
- package/dist/react/index.d.ts +44 -51
- package/dist/react/index.js +162 -164
- package/dist/sendTransaction-BHqCq_9X.d.ts +30 -0
- package/dist/sendTransaction-BKKYEt8p.d.cts +30 -0
- package/package.json +8 -5
- package/dist/chunk-3T2FNW6E.cjs +0 -100
- package/dist/chunk-BPFJZRJ6.cjs +0 -152
- package/dist/chunk-HOX3RRO6.js +0 -199
- package/dist/chunk-SGLR6RFA.cjs +0 -199
- package/dist/chunk-T54VMWHQ.js +0 -100
- package/dist/chunk-TPC5PMRC.js +0 -152
- package/dist/client--U_6SK0l.d.cts +0 -339
- package/dist/client-6_BJp7Ub.d.ts +0 -339
- package/dist/watchUnlockStatus-CxnibdQx.d.cts +0 -43
- package/dist/watchUnlockStatus-g8wIxpeM.d.ts +0 -43
package/dist/chunk-T54VMWHQ.js
DELETED
|
@@ -1,100 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
decompressDataAndCheckHash,
|
|
3
|
-
hashAndCompressData
|
|
4
|
-
} from "./chunk-TPC5PMRC.js";
|
|
5
|
-
|
|
6
|
-
// src/core/actions/getUnlockOptions.ts
|
|
7
|
-
function getArticleUnlockOptions(client, { articleId, contentId }) {
|
|
8
|
-
return client.request({
|
|
9
|
-
method: "frak_getArticleUnlockOptions",
|
|
10
|
-
params: [contentId, articleId]
|
|
11
|
-
});
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
// src/core/actions/watchUnlockStatus.ts
|
|
15
|
-
function watchUnlockStatus(client, { articleId, contentId }, callback) {
|
|
16
|
-
return client.listenerRequest(
|
|
17
|
-
{
|
|
18
|
-
method: "frak_listenToArticleUnlockStatus",
|
|
19
|
-
params: [contentId, articleId]
|
|
20
|
-
},
|
|
21
|
-
callback
|
|
22
|
-
);
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
// src/core/actions/watchWalletStatus.ts
|
|
26
|
-
function watchWalletStatus(client, callback) {
|
|
27
|
-
return client.listenerRequest(
|
|
28
|
-
{
|
|
29
|
-
method: "frak_listenToWalletStatus"
|
|
30
|
-
},
|
|
31
|
-
callback
|
|
32
|
-
);
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
// src/core/actions/startUnlock.ts
|
|
36
|
-
async function getStartArticleUnlockUrl(config, params) {
|
|
37
|
-
const { compressed, compressedHash } = await hashAndCompressData({
|
|
38
|
-
method: "frak_startArticleUnlock",
|
|
39
|
-
params
|
|
40
|
-
});
|
|
41
|
-
const outputUrl = new URL(config.walletUrl);
|
|
42
|
-
outputUrl.pathname = "/paywall";
|
|
43
|
-
outputUrl.searchParams.set("params", encodeURIComponent(compressed));
|
|
44
|
-
outputUrl.searchParams.set("hash", encodeURIComponent(compressedHash));
|
|
45
|
-
return outputUrl.toString();
|
|
46
|
-
}
|
|
47
|
-
async function decodeStartUnlockReturn({
|
|
48
|
-
result,
|
|
49
|
-
hash
|
|
50
|
-
}) {
|
|
51
|
-
return decompressDataAndCheckHash({
|
|
52
|
-
compressed: decodeURIComponent(result),
|
|
53
|
-
compressedHash: decodeURIComponent(hash)
|
|
54
|
-
});
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
// src/core/actions/sendTransaction.ts
|
|
58
|
-
async function sendTransaction(client, { tx, context }) {
|
|
59
|
-
return await client.request({
|
|
60
|
-
method: "frak_sendTransaction",
|
|
61
|
-
params: [tx, context]
|
|
62
|
-
});
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
// src/core/actions/siweAuthenticate.ts
|
|
66
|
-
import { generateSiweNonce } from "viem/siwe";
|
|
67
|
-
async function siweAuthenticate(client, { siwe, context }) {
|
|
68
|
-
const realStatement = siwe?.statement ?? `I confirm that I want to use my Nexus wallet on: ${client.config.metadata.name}`;
|
|
69
|
-
const builtSiwe = {
|
|
70
|
-
...siwe,
|
|
71
|
-
statement: realStatement,
|
|
72
|
-
nonce: siwe?.nonce ?? generateSiweNonce(),
|
|
73
|
-
uri: siwe?.uri ?? `https://${client.config.domain}`,
|
|
74
|
-
version: siwe?.version ?? "1",
|
|
75
|
-
domain: client.config.domain
|
|
76
|
-
};
|
|
77
|
-
return await client.request({
|
|
78
|
-
method: "frak_siweAuthenticate",
|
|
79
|
-
params: [builtSiwe, context]
|
|
80
|
-
});
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
// src/core/actions/sendInteraction.ts
|
|
84
|
-
async function sendInteraction(client, { contentId, interaction, validation }) {
|
|
85
|
-
return await client.request({
|
|
86
|
-
method: "frak_sendInteraction",
|
|
87
|
-
params: [contentId, interaction, validation]
|
|
88
|
-
});
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
export {
|
|
92
|
-
getArticleUnlockOptions,
|
|
93
|
-
watchUnlockStatus,
|
|
94
|
-
watchWalletStatus,
|
|
95
|
-
getStartArticleUnlockUrl,
|
|
96
|
-
decodeStartUnlockReturn,
|
|
97
|
-
sendTransaction,
|
|
98
|
-
siweAuthenticate,
|
|
99
|
-
sendInteraction
|
|
100
|
-
};
|
package/dist/chunk-TPC5PMRC.js
DELETED
|
@@ -1,152 +0,0 @@
|
|
|
1
|
-
// src/core/types/rpc/error.ts
|
|
2
|
-
var FrakRpcError = class extends Error {
|
|
3
|
-
constructor(code, message, data) {
|
|
4
|
-
super(message);
|
|
5
|
-
this.code = code;
|
|
6
|
-
this.data = data;
|
|
7
|
-
}
|
|
8
|
-
};
|
|
9
|
-
var ClientNotFound = class extends FrakRpcError {
|
|
10
|
-
constructor() {
|
|
11
|
-
super(RpcErrorCodes.clientNotConnected, "Client not found");
|
|
12
|
-
}
|
|
13
|
-
};
|
|
14
|
-
var RpcErrorCodes = {
|
|
15
|
-
// Standard JSON-RPC 2.0 errors
|
|
16
|
-
parseError: -32700,
|
|
17
|
-
invalidRequest: -32600,
|
|
18
|
-
methodNotFound: -32601,
|
|
19
|
-
invalidParams: -32602,
|
|
20
|
-
internalError: -32603,
|
|
21
|
-
serverError: -32e3,
|
|
22
|
-
// Frak specific errors (from -32001 to -32099)
|
|
23
|
-
clientNotConnected: -32001,
|
|
24
|
-
configError: -32002,
|
|
25
|
-
corruptedResponse: -32003,
|
|
26
|
-
clientAborted: -32004,
|
|
27
|
-
walletNotConnected: -32005,
|
|
28
|
-
noInteractionSession: -32006
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
// src/core/utils/compression/compress.ts
|
|
32
|
-
import { compressToBase64 } from "async-lz-string";
|
|
33
|
-
import { sha256 } from "js-sha256";
|
|
34
|
-
async function hashAndCompressData(data) {
|
|
35
|
-
const validationHash = sha256(JSON.stringify(data));
|
|
36
|
-
const hashProtectedData = {
|
|
37
|
-
...data,
|
|
38
|
-
validationHash
|
|
39
|
-
};
|
|
40
|
-
const compressed = await compressJson(hashProtectedData);
|
|
41
|
-
const compressedHash = sha256(compressed);
|
|
42
|
-
return {
|
|
43
|
-
compressed,
|
|
44
|
-
compressedHash
|
|
45
|
-
};
|
|
46
|
-
}
|
|
47
|
-
async function compressJson(data) {
|
|
48
|
-
return compressToBase64(JSON.stringify(data));
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
// src/core/utils/compression/decompress.ts
|
|
52
|
-
import { decompressFromBase64 } from "async-lz-string";
|
|
53
|
-
import { sha256 as sha2562 } from "js-sha256";
|
|
54
|
-
async function decompressDataAndCheckHash(compressedData) {
|
|
55
|
-
if (!(compressedData?.compressed && compressedData?.compressedHash)) {
|
|
56
|
-
throw new FrakRpcError(
|
|
57
|
-
RpcErrorCodes.corruptedResponse,
|
|
58
|
-
"Missing compressed data"
|
|
59
|
-
);
|
|
60
|
-
}
|
|
61
|
-
const parsedData = await decompressJson(
|
|
62
|
-
compressedData.compressed
|
|
63
|
-
);
|
|
64
|
-
if (!parsedData) {
|
|
65
|
-
throw new FrakRpcError(
|
|
66
|
-
RpcErrorCodes.corruptedResponse,
|
|
67
|
-
"Invalid compressed data"
|
|
68
|
-
);
|
|
69
|
-
}
|
|
70
|
-
if (!parsedData?.validationHash) {
|
|
71
|
-
throw new FrakRpcError(
|
|
72
|
-
RpcErrorCodes.corruptedResponse,
|
|
73
|
-
"Missing validation hash"
|
|
74
|
-
);
|
|
75
|
-
}
|
|
76
|
-
const expectedCompressedHash = sha2562(compressedData.compressed);
|
|
77
|
-
if (expectedCompressedHash !== compressedData.compressedHash) {
|
|
78
|
-
throw new FrakRpcError(
|
|
79
|
-
RpcErrorCodes.corruptedResponse,
|
|
80
|
-
"Invalid compressed hash"
|
|
81
|
-
);
|
|
82
|
-
}
|
|
83
|
-
const { validationHash: _, ...rawResultData } = parsedData;
|
|
84
|
-
const expectedValidationHash = sha2562(JSON.stringify(rawResultData));
|
|
85
|
-
if (expectedValidationHash !== parsedData.validationHash) {
|
|
86
|
-
throw new FrakRpcError(
|
|
87
|
-
RpcErrorCodes.corruptedResponse,
|
|
88
|
-
"Invalid data validation hash"
|
|
89
|
-
);
|
|
90
|
-
}
|
|
91
|
-
return parsedData;
|
|
92
|
-
}
|
|
93
|
-
async function decompressJson(data) {
|
|
94
|
-
const decompressed = await decompressFromBase64(data);
|
|
95
|
-
try {
|
|
96
|
-
return JSON.parse(decompressed);
|
|
97
|
-
} catch (e) {
|
|
98
|
-
console.error("Invalid compressed data", e);
|
|
99
|
-
return null;
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
// src/core/utils/iframeHelper.ts
|
|
104
|
-
function createIframe({
|
|
105
|
-
walletBaseUrl
|
|
106
|
-
}) {
|
|
107
|
-
const alreadyCreatedIFrame = document.querySelector("#nexus-wallet");
|
|
108
|
-
if (alreadyCreatedIFrame) {
|
|
109
|
-
return Promise.resolve(void 0);
|
|
110
|
-
}
|
|
111
|
-
const iframe = document.createElement("iframe");
|
|
112
|
-
iframe.name = "nexus-wallet";
|
|
113
|
-
iframe.id = "nexus-wallet";
|
|
114
|
-
iframe.style.zIndex = "1000";
|
|
115
|
-
changeIframeVisibility({ iframe, isVisible: false });
|
|
116
|
-
document.body.appendChild(iframe);
|
|
117
|
-
return new Promise((resolve) => {
|
|
118
|
-
iframe?.addEventListener("load", () => resolve(iframe));
|
|
119
|
-
iframe.src = `${walletBaseUrl}/listener`;
|
|
120
|
-
});
|
|
121
|
-
}
|
|
122
|
-
function changeIframeVisibility({
|
|
123
|
-
iframe,
|
|
124
|
-
isVisible
|
|
125
|
-
}) {
|
|
126
|
-
if (!isVisible) {
|
|
127
|
-
iframe.style.width = "0";
|
|
128
|
-
iframe.style.height = "0";
|
|
129
|
-
iframe.style.border = "0";
|
|
130
|
-
iframe.style.position = "fixed";
|
|
131
|
-
iframe.style.top = "-1000px";
|
|
132
|
-
iframe.style.left = "-1000px";
|
|
133
|
-
return;
|
|
134
|
-
}
|
|
135
|
-
iframe.style.position = "fixed";
|
|
136
|
-
iframe.style.top = "0";
|
|
137
|
-
iframe.style.left = "0";
|
|
138
|
-
iframe.style.width = "100%";
|
|
139
|
-
iframe.style.height = "100%";
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
export {
|
|
143
|
-
FrakRpcError,
|
|
144
|
-
ClientNotFound,
|
|
145
|
-
RpcErrorCodes,
|
|
146
|
-
hashAndCompressData,
|
|
147
|
-
compressJson,
|
|
148
|
-
decompressDataAndCheckHash,
|
|
149
|
-
decompressJson,
|
|
150
|
-
createIframe,
|
|
151
|
-
changeIframeVisibility
|
|
152
|
-
};
|
|
@@ -1,339 +0,0 @@
|
|
|
1
|
-
import { Hex, Address, RpcSchema } from 'viem';
|
|
2
|
-
import { Prettify } from 'viem/chains';
|
|
3
|
-
import { SiweMessage } from 'viem/siwe';
|
|
4
|
-
import { P as PreparedInteraction, a as SendInteractionReturnType } from './interaction-D_CzyqRE.cjs';
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Configuration for the Nexus Wallet SDK
|
|
8
|
-
*/
|
|
9
|
-
type NexusWalletSdkConfig = Readonly<{
|
|
10
|
-
walletUrl: string;
|
|
11
|
-
metadata: {
|
|
12
|
-
name: string;
|
|
13
|
-
};
|
|
14
|
-
domain: string;
|
|
15
|
-
}>;
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* Parameters of the send transaction rpc request
|
|
19
|
-
*/
|
|
20
|
-
type SiweAuthenticationParams = Omit<SiweMessage, "address" | "chainId">;
|
|
21
|
-
/**
|
|
22
|
-
* Same stuff but in an object format for better readability
|
|
23
|
-
*/
|
|
24
|
-
type SiweAuthenticateActionParamsType = Readonly<{
|
|
25
|
-
siwe?: Partial<SiweAuthenticationParams>;
|
|
26
|
-
context?: string;
|
|
27
|
-
}>;
|
|
28
|
-
/**
|
|
29
|
-
* Return type of the send transaction rpc request
|
|
30
|
-
*/
|
|
31
|
-
type SiweAuthenticateReturnType = Readonly<{
|
|
32
|
-
signature: Hex;
|
|
33
|
-
message: string;
|
|
34
|
-
}>;
|
|
35
|
-
|
|
36
|
-
/**
|
|
37
|
-
* Parameters of the send transaction rpc request
|
|
38
|
-
*/
|
|
39
|
-
type SendTransactionRpcParamsType = [
|
|
40
|
-
tx: SendTransactionTxType | SendTransactionTxType[],
|
|
41
|
-
context?: string
|
|
42
|
-
];
|
|
43
|
-
/**
|
|
44
|
-
* Same stuff but in an object format for better readability
|
|
45
|
-
*/
|
|
46
|
-
type SendTransactionActionParamsType = Readonly<{
|
|
47
|
-
tx: SendTransactionTxType | SendTransactionTxType[];
|
|
48
|
-
context?: string;
|
|
49
|
-
}>;
|
|
50
|
-
type SendTransactionTxType = Readonly<{
|
|
51
|
-
to: Address;
|
|
52
|
-
data: Hex;
|
|
53
|
-
value: Hex;
|
|
54
|
-
}>;
|
|
55
|
-
/**
|
|
56
|
-
* Return type of the send transaction rpc request
|
|
57
|
-
*/
|
|
58
|
-
type SendTransactionReturnType = Readonly<{
|
|
59
|
-
hash: Hex;
|
|
60
|
-
}>;
|
|
61
|
-
|
|
62
|
-
type PaidArticleUnlockPrice = Readonly<{
|
|
63
|
-
index: number;
|
|
64
|
-
unlockDurationInSec: number;
|
|
65
|
-
frkAmount: Hex;
|
|
66
|
-
}>;
|
|
67
|
-
|
|
68
|
-
/**
|
|
69
|
-
* Request to unlock a paid article
|
|
70
|
-
*/
|
|
71
|
-
type StartArticleUnlockParams = Readonly<{
|
|
72
|
-
articleId: Hex;
|
|
73
|
-
contentId: Hex;
|
|
74
|
-
imageUrl: string;
|
|
75
|
-
articleTitle: string;
|
|
76
|
-
contentTitle: string;
|
|
77
|
-
price: PaidArticleUnlockPrice;
|
|
78
|
-
articleUrl: string;
|
|
79
|
-
redirectUrl: string;
|
|
80
|
-
previewUrl?: string;
|
|
81
|
-
provider: "le-monde" | "wired" | "l-equipe";
|
|
82
|
-
}>;
|
|
83
|
-
/**
|
|
84
|
-
* Return type of the unlock request
|
|
85
|
-
*/
|
|
86
|
-
type StartArticleUnlockReturnType = UnlockSuccess | AlreadyUnlocked | UnlockError;
|
|
87
|
-
type UnlockSuccess = {
|
|
88
|
-
key: "success";
|
|
89
|
-
status: "in-progress";
|
|
90
|
-
user: Address;
|
|
91
|
-
userOpHash: Hex;
|
|
92
|
-
};
|
|
93
|
-
type AlreadyUnlocked = {
|
|
94
|
-
key: "already-unlocked";
|
|
95
|
-
status: "unlocked";
|
|
96
|
-
user: Address;
|
|
97
|
-
};
|
|
98
|
-
type UnlockError = {
|
|
99
|
-
key: "error" | "cancelled";
|
|
100
|
-
status: "locked";
|
|
101
|
-
user?: Address;
|
|
102
|
-
reason?: string;
|
|
103
|
-
};
|
|
104
|
-
|
|
105
|
-
/**
|
|
106
|
-
* The response to the get unlock options response
|
|
107
|
-
*/
|
|
108
|
-
type UnlockOptionsReturnType = Readonly<{
|
|
109
|
-
frkBalanceAsHex?: Hex;
|
|
110
|
-
prices: {
|
|
111
|
-
index: number;
|
|
112
|
-
unlockDurationInSec: number;
|
|
113
|
-
frkAmount: Hex;
|
|
114
|
-
isUserAccessible: boolean | null;
|
|
115
|
-
}[];
|
|
116
|
-
}>;
|
|
117
|
-
|
|
118
|
-
/**
|
|
119
|
-
* The different types of response for the current unlock status
|
|
120
|
-
*/
|
|
121
|
-
type ArticleUnlockStatusReturnType = Readonly<UnlockStatusLocked | UnlockStatusProcessing | UnlockStatusValid | UnlockStatusError>;
|
|
122
|
-
/**
|
|
123
|
-
* When the content unlocked was expired or not unlocked
|
|
124
|
-
*/
|
|
125
|
-
type UnlockStatusLocked = {
|
|
126
|
-
key: "expired";
|
|
127
|
-
status: "locked";
|
|
128
|
-
expiredAt: number;
|
|
129
|
-
} | {
|
|
130
|
-
key: "not-unlocked";
|
|
131
|
-
status: "locked";
|
|
132
|
-
};
|
|
133
|
-
/**
|
|
134
|
-
* When the content unlock is in progress
|
|
135
|
-
*/
|
|
136
|
-
type UnlockStatusProcessing = {
|
|
137
|
-
status: "in-progress";
|
|
138
|
-
} & ({
|
|
139
|
-
key: "preparing" | "waiting-user-validation";
|
|
140
|
-
} | {
|
|
141
|
-
key: "waiting-transaction-bundling";
|
|
142
|
-
userOpHash: Hex;
|
|
143
|
-
} | {
|
|
144
|
-
key: "waiting-transaction-confirmation";
|
|
145
|
-
userOpHash: Hex;
|
|
146
|
-
txHash: Hex;
|
|
147
|
-
});
|
|
148
|
-
/**
|
|
149
|
-
* When the content is unlocked
|
|
150
|
-
*/
|
|
151
|
-
type UnlockStatusValid = {
|
|
152
|
-
key: "valid";
|
|
153
|
-
status: "unlocked";
|
|
154
|
-
allowedUntil: number;
|
|
155
|
-
};
|
|
156
|
-
/**
|
|
157
|
-
* When the unlock content is in error
|
|
158
|
-
*/
|
|
159
|
-
type UnlockStatusError = {
|
|
160
|
-
key: "error";
|
|
161
|
-
status: "locked";
|
|
162
|
-
reason: string;
|
|
163
|
-
};
|
|
164
|
-
|
|
165
|
-
type WalletStatusReturnType = Readonly<WalletConnected | WalletNotConnected>;
|
|
166
|
-
type WalletConnected = {
|
|
167
|
-
key: "connected";
|
|
168
|
-
wallet: Address;
|
|
169
|
-
};
|
|
170
|
-
type WalletNotConnected = {
|
|
171
|
-
key: "not-connected";
|
|
172
|
-
};
|
|
173
|
-
|
|
174
|
-
/**
|
|
175
|
-
* RPC interface that's used for the iframe communication
|
|
176
|
-
*/
|
|
177
|
-
type IFrameRpcSchema = [
|
|
178
|
-
/**
|
|
179
|
-
* Method used to fetch an article unlock options
|
|
180
|
-
*/
|
|
181
|
-
{
|
|
182
|
-
Method: "frak_getArticleUnlockOptions";
|
|
183
|
-
Parameters: [contentId: Hex, articleId: Hex];
|
|
184
|
-
ReturnType: UnlockOptionsReturnType;
|
|
185
|
-
},
|
|
186
|
-
/**
|
|
187
|
-
* Method used to listen to the wallet status
|
|
188
|
-
*/
|
|
189
|
-
{
|
|
190
|
-
Method: "frak_listenToWalletStatus";
|
|
191
|
-
Parameters?: undefined;
|
|
192
|
-
ReturnType: WalletStatusReturnType;
|
|
193
|
-
},
|
|
194
|
-
/**
|
|
195
|
-
* Method used to listen to an article unlock status
|
|
196
|
-
*/
|
|
197
|
-
{
|
|
198
|
-
Method: "frak_listenToArticleUnlockStatus";
|
|
199
|
-
Parameters: [contentId: Hex, articleId: Hex];
|
|
200
|
-
ReturnType: ArticleUnlockStatusReturnType;
|
|
201
|
-
},
|
|
202
|
-
/**
|
|
203
|
-
* Method to ask the user to send a transaction
|
|
204
|
-
*/
|
|
205
|
-
{
|
|
206
|
-
Method: "frak_sendTransaction";
|
|
207
|
-
Parameters: SendTransactionRpcParamsType;
|
|
208
|
-
ReturnType: SendTransactionReturnType;
|
|
209
|
-
},
|
|
210
|
-
/**
|
|
211
|
-
* Method to ask the user for a strong authentication
|
|
212
|
-
*/
|
|
213
|
-
{
|
|
214
|
-
Method: "frak_siweAuthenticate";
|
|
215
|
-
Parameters: [request: SiweAuthenticationParams, context?: string];
|
|
216
|
-
ReturnType: SiweAuthenticateReturnType;
|
|
217
|
-
},
|
|
218
|
-
/**
|
|
219
|
-
* Method to transmit a user interaction
|
|
220
|
-
*/
|
|
221
|
-
{
|
|
222
|
-
Method: "frak_sendInteraction";
|
|
223
|
-
Parameters: [
|
|
224
|
-
contentId: Hex,
|
|
225
|
-
interaction: PreparedInteraction,
|
|
226
|
-
signature?: Hex
|
|
227
|
-
];
|
|
228
|
-
ReturnType: SendInteractionReturnType;
|
|
229
|
-
}
|
|
230
|
-
];
|
|
231
|
-
/**
|
|
232
|
-
* RPC interface that's used for the redirection communication
|
|
233
|
-
*/
|
|
234
|
-
type RedirectRpcSchema = [
|
|
235
|
-
/**
|
|
236
|
-
* Method used to start the unlock of an article
|
|
237
|
-
*/
|
|
238
|
-
{
|
|
239
|
-
Method: "frak_startArticleUnlock";
|
|
240
|
-
Path: "/paywall";
|
|
241
|
-
Parameters: StartArticleUnlockParams;
|
|
242
|
-
ReturnType: StartArticleUnlockReturnType;
|
|
243
|
-
}
|
|
244
|
-
];
|
|
245
|
-
|
|
246
|
-
/**
|
|
247
|
-
* Type that extract the possible parameters from a RPC Schema
|
|
248
|
-
*/
|
|
249
|
-
type ExtractedParametersFromRpc<TRpcSchema extends RpcSchema> = {
|
|
250
|
-
[K in keyof TRpcSchema]: Prettify<{
|
|
251
|
-
method: TRpcSchema[K] extends TRpcSchema[number] ? TRpcSchema[K]["Method"] : string;
|
|
252
|
-
} & (TRpcSchema[K] extends TRpcSchema[number] ? TRpcSchema[K]["Parameters"] extends undefined ? {
|
|
253
|
-
params?: never;
|
|
254
|
-
} : {
|
|
255
|
-
params: TRpcSchema[K]["Parameters"];
|
|
256
|
-
} : never)>;
|
|
257
|
-
}[number];
|
|
258
|
-
/**
|
|
259
|
-
* Type that extract the possible return type from a RPC Schema
|
|
260
|
-
*/
|
|
261
|
-
type ExtractedReturnTypeFromRpc<TRpcSchema extends RpcSchema, TParameters extends ExtractedParametersFromRpc<TRpcSchema> = ExtractedParametersFromRpc<TRpcSchema>> = ExtractedMethodFromRpc<TRpcSchema, TParameters["method"]>["ReturnType"];
|
|
262
|
-
/**
|
|
263
|
-
* Type that extract the possible return type from a RPC Schema
|
|
264
|
-
*/
|
|
265
|
-
type ExtractedMethodFromRpc<TRpcSchema extends RpcSchema, TMethod extends ExtractedParametersFromRpc<TRpcSchema>["method"] = ExtractedParametersFromRpc<TRpcSchema>["method"]> = Extract<TRpcSchema[number], {
|
|
266
|
-
Method: TMethod;
|
|
267
|
-
}>;
|
|
268
|
-
/**
|
|
269
|
-
* Raw response that we will receive after an rpc request
|
|
270
|
-
*/
|
|
271
|
-
type RpcResponse<TRpcSchema extends RpcSchema, TMethod extends TRpcSchema[number]["Method"] = TRpcSchema[number]["Method"]> = {
|
|
272
|
-
result: Extract<TRpcSchema[number], {
|
|
273
|
-
Method: TMethod;
|
|
274
|
-
}>["ReturnType"];
|
|
275
|
-
error?: never;
|
|
276
|
-
} | {
|
|
277
|
-
result?: never;
|
|
278
|
-
error: {
|
|
279
|
-
code: number;
|
|
280
|
-
message: string;
|
|
281
|
-
data?: unknown;
|
|
282
|
-
};
|
|
283
|
-
};
|
|
284
|
-
/**
|
|
285
|
-
* Type used for a one shot request function
|
|
286
|
-
*/
|
|
287
|
-
type RequestFn<TRpcSchema extends RpcSchema> = <TParameters extends ExtractedParametersFromRpc<TRpcSchema> = ExtractedParametersFromRpc<TRpcSchema>, _ReturnType = ExtractedReturnTypeFromRpc<TRpcSchema, TParameters>>(args: TParameters) => Promise<_ReturnType>;
|
|
288
|
-
/**
|
|
289
|
-
* Type used for a one shot request function
|
|
290
|
-
*/
|
|
291
|
-
type ListenerRequestFn<TRpcSchema extends RpcSchema> = <TParameters extends ExtractedParametersFromRpc<TRpcSchema> = ExtractedParametersFromRpc<TRpcSchema>>(args: TParameters, callback: (result: ExtractedReturnTypeFromRpc<TRpcSchema, TParameters>) => void) => Promise<void>;
|
|
292
|
-
/**
|
|
293
|
-
* IFrame transport interface
|
|
294
|
-
*/
|
|
295
|
-
type IFrameTransport = {
|
|
296
|
-
/**
|
|
297
|
-
* Wait for the connection to be established
|
|
298
|
-
*/
|
|
299
|
-
waitForConnection: Promise<boolean>;
|
|
300
|
-
/**
|
|
301
|
-
* Function used to perform a single request via the iframe transport
|
|
302
|
-
*/
|
|
303
|
-
request: RequestFn<IFrameRpcSchema>;
|
|
304
|
-
/**
|
|
305
|
-
* Function used to listen to a request response via the iframe transport
|
|
306
|
-
*/
|
|
307
|
-
listenerRequest: ListenerRequestFn<IFrameRpcSchema>;
|
|
308
|
-
/**
|
|
309
|
-
* Function used to destroy the iframe transport
|
|
310
|
-
*/
|
|
311
|
-
destroy: () => Promise<void>;
|
|
312
|
-
};
|
|
313
|
-
/**
|
|
314
|
-
* Represent an iframe event
|
|
315
|
-
*/
|
|
316
|
-
type IFrameEvent = IFrameRpcEvent | IFrameLifecycleEvent;
|
|
317
|
-
/**
|
|
318
|
-
* Represent an iframe rpc event
|
|
319
|
-
*/
|
|
320
|
-
type IFrameRpcEvent = {
|
|
321
|
-
id: string;
|
|
322
|
-
topic: ExtractedParametersFromRpc<IFrameRpcSchema>["method"];
|
|
323
|
-
data: {
|
|
324
|
-
compressed: string;
|
|
325
|
-
compressedHash: string;
|
|
326
|
-
};
|
|
327
|
-
};
|
|
328
|
-
type IFrameLifecycleEvent = {
|
|
329
|
-
lifecycle: "connected" | "show" | "hide";
|
|
330
|
-
};
|
|
331
|
-
|
|
332
|
-
/**
|
|
333
|
-
* Representing a Nexus client
|
|
334
|
-
*/
|
|
335
|
-
type NexusClient = {
|
|
336
|
-
config: NexusWalletSdkConfig;
|
|
337
|
-
} & IFrameTransport;
|
|
338
|
-
|
|
339
|
-
export type { ArticleUnlockStatusReturnType as A, ExtractedParametersFromRpc as E, IFrameRpcSchema as I, NexusClient as N, PaidArticleUnlockPrice as P, RedirectRpcSchema as R, StartArticleUnlockParams as S, UnlockOptionsReturnType as U, WalletStatusReturnType as W, NexusWalletSdkConfig as a, StartArticleUnlockReturnType as b, SendTransactionActionParamsType as c, SendTransactionReturnType as d, SendTransactionTxType as e, SiweAuthenticateReturnType as f, SiweAuthenticateActionParamsType as g, SiweAuthenticationParams as h, RpcResponse as i, IFrameTransport as j, IFrameRpcEvent as k, IFrameEvent as l, ExtractedReturnTypeFromRpc as m };
|