@frak-labs/nexus-sdk 0.0.8 → 0.0.10
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-3T2FNW6E.cjs +100 -0
- package/dist/chunk-72IEHEQX.js +48 -0
- package/dist/chunk-BPFJZRJ6.cjs +152 -0
- package/dist/chunk-ETV4XYOV.cjs +7 -0
- package/dist/{chunk-OXP3VK26.js → chunk-HOX3RRO6.js} +58 -30
- package/dist/chunk-NIFJZD3M.cjs +48 -0
- package/dist/chunk-PKBMQBKP.js +7 -0
- package/dist/{chunk-JXQKTLEE.cjs → chunk-SGLR6RFA.cjs} +59 -31
- package/dist/chunk-T54VMWHQ.js +100 -0
- package/dist/chunk-TPC5PMRC.js +152 -0
- package/dist/{client-MgLVRfPw.d.cts → client--U_6SK0l.d.cts} +101 -12
- package/dist/{client-MgLVRfPw.d.ts → client-6_BJp7Ub.d.ts} +101 -12
- package/dist/core/actions/index.cjs +10 -3
- package/dist/core/actions/index.d.cts +31 -3
- package/dist/core/actions/index.d.ts +31 -3
- package/dist/core/actions/index.js +9 -2
- package/dist/core/index.cjs +4 -7
- package/dist/core/index.d.cts +8 -35
- package/dist/core/index.d.ts +8 -35
- package/dist/core/index.js +9 -12
- package/dist/core/interactions/index.cjs +9 -0
- package/dist/core/interactions/index.d.cts +39 -0
- package/dist/core/interactions/index.d.ts +39 -0
- package/dist/core/interactions/index.js +9 -0
- package/dist/error-C4Zm5nQe.d.cts +27 -0
- package/dist/error-C4Zm5nQe.d.ts +27 -0
- package/dist/interaction-D_CzyqRE.d.cts +22 -0
- package/dist/interaction-D_CzyqRE.d.ts +22 -0
- package/dist/react/index.cjs +276 -42
- package/dist/react/index.d.cts +72 -12
- package/dist/react/index.d.ts +72 -12
- package/dist/react/index.js +272 -38
- package/dist/{watchUnlockStatus-DQYfUj46.d.ts → watchUnlockStatus-CxnibdQx.d.cts} +3 -3
- package/dist/{watchUnlockStatus-DqWkImYK.d.cts → watchUnlockStatus-g8wIxpeM.d.ts} +3 -3
- package/package.json +11 -5
- package/dist/chunk-2XUJYDD3.cjs +0 -160
- package/dist/chunk-4VFMYMTH.js +0 -74
- package/dist/chunk-5QWG35A2.js +0 -160
- package/dist/chunk-6V4UCVTD.cjs +0 -74
|
@@ -0,0 +1,100 @@
|
|
|
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
|
+
};
|
|
@@ -0,0 +1,152 @@
|
|
|
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,5 +1,7 @@
|
|
|
1
1
|
import { Hex, Address, RpcSchema } from 'viem';
|
|
2
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';
|
|
3
5
|
|
|
4
6
|
/**
|
|
5
7
|
* Configuration for the Nexus Wallet SDK
|
|
@@ -9,6 +11,52 @@ type NexusWalletSdkConfig = Readonly<{
|
|
|
9
11
|
metadata: {
|
|
10
12
|
name: string;
|
|
11
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;
|
|
12
60
|
}>;
|
|
13
61
|
|
|
14
62
|
type PaidArticleUnlockPrice = Readonly<{
|
|
@@ -150,6 +198,34 @@ type IFrameRpcSchema = [
|
|
|
150
198
|
Method: "frak_listenToArticleUnlockStatus";
|
|
151
199
|
Parameters: [contentId: Hex, articleId: Hex];
|
|
152
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;
|
|
153
229
|
}
|
|
154
230
|
];
|
|
155
231
|
/**
|
|
@@ -170,7 +246,7 @@ type RedirectRpcSchema = [
|
|
|
170
246
|
/**
|
|
171
247
|
* Type that extract the possible parameters from a RPC Schema
|
|
172
248
|
*/
|
|
173
|
-
type ExtractedParametersFromRpc<TRpcSchema extends RpcSchema
|
|
249
|
+
type ExtractedParametersFromRpc<TRpcSchema extends RpcSchema> = {
|
|
174
250
|
[K in keyof TRpcSchema]: Prettify<{
|
|
175
251
|
method: TRpcSchema[K] extends TRpcSchema[number] ? TRpcSchema[K]["Method"] : string;
|
|
176
252
|
} & (TRpcSchema[K] extends TRpcSchema[number] ? TRpcSchema[K]["Parameters"] extends undefined ? {
|
|
@@ -178,28 +254,41 @@ type ExtractedParametersFromRpc<TRpcSchema extends RpcSchema | undefined = undef
|
|
|
178
254
|
} : {
|
|
179
255
|
params: TRpcSchema[K]["Parameters"];
|
|
180
256
|
} : never)>;
|
|
181
|
-
}[number]
|
|
182
|
-
method: string;
|
|
183
|
-
params?: unknown;
|
|
184
|
-
};
|
|
257
|
+
}[number];
|
|
185
258
|
/**
|
|
186
259
|
* Type that extract the possible return type from a RPC Schema
|
|
187
260
|
*/
|
|
188
|
-
type ExtractedReturnTypeFromRpc<TRpcSchema extends RpcSchema
|
|
261
|
+
type ExtractedReturnTypeFromRpc<TRpcSchema extends RpcSchema, TParameters extends ExtractedParametersFromRpc<TRpcSchema> = ExtractedParametersFromRpc<TRpcSchema>> = ExtractedMethodFromRpc<TRpcSchema, TParameters["method"]>["ReturnType"];
|
|
189
262
|
/**
|
|
190
263
|
* Type that extract the possible return type from a RPC Schema
|
|
191
264
|
*/
|
|
192
|
-
type ExtractedMethodFromRpc<TRpcSchema extends RpcSchema
|
|
265
|
+
type ExtractedMethodFromRpc<TRpcSchema extends RpcSchema, TMethod extends ExtractedParametersFromRpc<TRpcSchema>["method"] = ExtractedParametersFromRpc<TRpcSchema>["method"]> = Extract<TRpcSchema[number], {
|
|
193
266
|
Method: TMethod;
|
|
194
|
-
}
|
|
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
|
+
};
|
|
195
284
|
/**
|
|
196
285
|
* Type used for a one shot request function
|
|
197
286
|
*/
|
|
198
|
-
type RequestFn<TRpcSchema extends RpcSchema
|
|
287
|
+
type RequestFn<TRpcSchema extends RpcSchema> = <TParameters extends ExtractedParametersFromRpc<TRpcSchema> = ExtractedParametersFromRpc<TRpcSchema>, _ReturnType = ExtractedReturnTypeFromRpc<TRpcSchema, TParameters>>(args: TParameters) => Promise<_ReturnType>;
|
|
199
288
|
/**
|
|
200
289
|
* Type used for a one shot request function
|
|
201
290
|
*/
|
|
202
|
-
type ListenerRequestFn<TRpcSchema extends RpcSchema
|
|
291
|
+
type ListenerRequestFn<TRpcSchema extends RpcSchema> = <TParameters extends ExtractedParametersFromRpc<TRpcSchema> = ExtractedParametersFromRpc<TRpcSchema>>(args: TParameters, callback: (result: ExtractedReturnTypeFromRpc<TRpcSchema, TParameters>) => void) => Promise<void>;
|
|
203
292
|
/**
|
|
204
293
|
* IFrame transport interface
|
|
205
294
|
*/
|
|
@@ -237,7 +326,7 @@ type IFrameRpcEvent = {
|
|
|
237
326
|
};
|
|
238
327
|
};
|
|
239
328
|
type IFrameLifecycleEvent = {
|
|
240
|
-
lifecycle: "connected";
|
|
329
|
+
lifecycle: "connected" | "show" | "hide";
|
|
241
330
|
};
|
|
242
331
|
|
|
243
332
|
/**
|
|
@@ -247,4 +336,4 @@ type NexusClient = {
|
|
|
247
336
|
config: NexusWalletSdkConfig;
|
|
248
337
|
} & IFrameTransport;
|
|
249
338
|
|
|
250
|
-
export type { ArticleUnlockStatusReturnType as A, ExtractedParametersFromRpc as E, IFrameRpcSchema as I, NexusClient as N, PaidArticleUnlockPrice as P, RedirectRpcSchema as R,
|
|
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 };
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { Hex, Address, RpcSchema } from 'viem';
|
|
2
2
|
import { Prettify } from 'viem/chains';
|
|
3
|
+
import { SiweMessage } from 'viem/siwe';
|
|
4
|
+
import { P as PreparedInteraction, a as SendInteractionReturnType } from './interaction-D_CzyqRE.js';
|
|
3
5
|
|
|
4
6
|
/**
|
|
5
7
|
* Configuration for the Nexus Wallet SDK
|
|
@@ -9,6 +11,52 @@ type NexusWalletSdkConfig = Readonly<{
|
|
|
9
11
|
metadata: {
|
|
10
12
|
name: string;
|
|
11
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;
|
|
12
60
|
}>;
|
|
13
61
|
|
|
14
62
|
type PaidArticleUnlockPrice = Readonly<{
|
|
@@ -150,6 +198,34 @@ type IFrameRpcSchema = [
|
|
|
150
198
|
Method: "frak_listenToArticleUnlockStatus";
|
|
151
199
|
Parameters: [contentId: Hex, articleId: Hex];
|
|
152
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;
|
|
153
229
|
}
|
|
154
230
|
];
|
|
155
231
|
/**
|
|
@@ -170,7 +246,7 @@ type RedirectRpcSchema = [
|
|
|
170
246
|
/**
|
|
171
247
|
* Type that extract the possible parameters from a RPC Schema
|
|
172
248
|
*/
|
|
173
|
-
type ExtractedParametersFromRpc<TRpcSchema extends RpcSchema
|
|
249
|
+
type ExtractedParametersFromRpc<TRpcSchema extends RpcSchema> = {
|
|
174
250
|
[K in keyof TRpcSchema]: Prettify<{
|
|
175
251
|
method: TRpcSchema[K] extends TRpcSchema[number] ? TRpcSchema[K]["Method"] : string;
|
|
176
252
|
} & (TRpcSchema[K] extends TRpcSchema[number] ? TRpcSchema[K]["Parameters"] extends undefined ? {
|
|
@@ -178,28 +254,41 @@ type ExtractedParametersFromRpc<TRpcSchema extends RpcSchema | undefined = undef
|
|
|
178
254
|
} : {
|
|
179
255
|
params: TRpcSchema[K]["Parameters"];
|
|
180
256
|
} : never)>;
|
|
181
|
-
}[number]
|
|
182
|
-
method: string;
|
|
183
|
-
params?: unknown;
|
|
184
|
-
};
|
|
257
|
+
}[number];
|
|
185
258
|
/**
|
|
186
259
|
* Type that extract the possible return type from a RPC Schema
|
|
187
260
|
*/
|
|
188
|
-
type ExtractedReturnTypeFromRpc<TRpcSchema extends RpcSchema
|
|
261
|
+
type ExtractedReturnTypeFromRpc<TRpcSchema extends RpcSchema, TParameters extends ExtractedParametersFromRpc<TRpcSchema> = ExtractedParametersFromRpc<TRpcSchema>> = ExtractedMethodFromRpc<TRpcSchema, TParameters["method"]>["ReturnType"];
|
|
189
262
|
/**
|
|
190
263
|
* Type that extract the possible return type from a RPC Schema
|
|
191
264
|
*/
|
|
192
|
-
type ExtractedMethodFromRpc<TRpcSchema extends RpcSchema
|
|
265
|
+
type ExtractedMethodFromRpc<TRpcSchema extends RpcSchema, TMethod extends ExtractedParametersFromRpc<TRpcSchema>["method"] = ExtractedParametersFromRpc<TRpcSchema>["method"]> = Extract<TRpcSchema[number], {
|
|
193
266
|
Method: TMethod;
|
|
194
|
-
}
|
|
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
|
+
};
|
|
195
284
|
/**
|
|
196
285
|
* Type used for a one shot request function
|
|
197
286
|
*/
|
|
198
|
-
type RequestFn<TRpcSchema extends RpcSchema
|
|
287
|
+
type RequestFn<TRpcSchema extends RpcSchema> = <TParameters extends ExtractedParametersFromRpc<TRpcSchema> = ExtractedParametersFromRpc<TRpcSchema>, _ReturnType = ExtractedReturnTypeFromRpc<TRpcSchema, TParameters>>(args: TParameters) => Promise<_ReturnType>;
|
|
199
288
|
/**
|
|
200
289
|
* Type used for a one shot request function
|
|
201
290
|
*/
|
|
202
|
-
type ListenerRequestFn<TRpcSchema extends RpcSchema
|
|
291
|
+
type ListenerRequestFn<TRpcSchema extends RpcSchema> = <TParameters extends ExtractedParametersFromRpc<TRpcSchema> = ExtractedParametersFromRpc<TRpcSchema>>(args: TParameters, callback: (result: ExtractedReturnTypeFromRpc<TRpcSchema, TParameters>) => void) => Promise<void>;
|
|
203
292
|
/**
|
|
204
293
|
* IFrame transport interface
|
|
205
294
|
*/
|
|
@@ -237,7 +326,7 @@ type IFrameRpcEvent = {
|
|
|
237
326
|
};
|
|
238
327
|
};
|
|
239
328
|
type IFrameLifecycleEvent = {
|
|
240
|
-
lifecycle: "connected";
|
|
329
|
+
lifecycle: "connected" | "show" | "hide";
|
|
241
330
|
};
|
|
242
331
|
|
|
243
332
|
/**
|
|
@@ -247,4 +336,4 @@ type NexusClient = {
|
|
|
247
336
|
config: NexusWalletSdkConfig;
|
|
248
337
|
} & IFrameTransport;
|
|
249
338
|
|
|
250
|
-
export type { ArticleUnlockStatusReturnType as A, ExtractedParametersFromRpc as E, IFrameRpcSchema as I, NexusClient as N, PaidArticleUnlockPrice as P, RedirectRpcSchema as R,
|
|
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 };
|
|
@@ -4,12 +4,19 @@
|
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
|
|
7
|
-
var _chunk6V4UCVTDcjs = require('../../chunk-6V4UCVTD.cjs');
|
|
8
|
-
require('../../chunk-2XUJYDD3.cjs');
|
|
9
7
|
|
|
10
8
|
|
|
11
9
|
|
|
10
|
+
var _chunk3T2FNW6Ecjs = require('../../chunk-3T2FNW6E.cjs');
|
|
11
|
+
require('../../chunk-BPFJZRJ6.cjs');
|
|
12
|
+
require('../../chunk-ETV4XYOV.cjs');
|
|
12
13
|
|
|
13
14
|
|
|
14
15
|
|
|
15
|
-
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
exports.decodeStartUnlockReturn = _chunk3T2FNW6Ecjs.decodeStartUnlockReturn; exports.getArticleUnlockOptions = _chunk3T2FNW6Ecjs.getArticleUnlockOptions; exports.getStartArticleUnlockUrl = _chunk3T2FNW6Ecjs.getStartArticleUnlockUrl; exports.sendInteraction = _chunk3T2FNW6Ecjs.sendInteraction; exports.sendTransaction = _chunk3T2FNW6Ecjs.sendTransaction; exports.siweAuthenticate = _chunk3T2FNW6Ecjs.siweAuthenticate; exports.watchUnlockStatus = _chunk3T2FNW6Ecjs.watchUnlockStatus; exports.watchWalletStatus = _chunk3T2FNW6Ecjs.watchWalletStatus;
|
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
export { G as GetUnlockOptionsParams, W as WatchUnlockStatusParams, g as getArticleUnlockOptions, w as watchUnlockStatus } from '../../watchUnlockStatus-
|
|
2
|
-
import { N as NexusClient, W as WalletStatusReturnType, a as NexusWalletSdkConfig,
|
|
1
|
+
export { G as GetUnlockOptionsParams, W as WatchUnlockStatusParams, g as getArticleUnlockOptions, w as watchUnlockStatus } from '../../watchUnlockStatus-CxnibdQx.cjs';
|
|
2
|
+
import { N as NexusClient, W as WalletStatusReturnType, a as NexusWalletSdkConfig, b as StartArticleUnlockReturnType, S as StartArticleUnlockParams, c as SendTransactionActionParamsType, d as SendTransactionReturnType, g as SiweAuthenticateActionParamsType, f as SiweAuthenticateReturnType } from '../../client--U_6SK0l.cjs';
|
|
3
|
+
import { S as SendInteractionParamsType, a as SendInteractionReturnType } from '../../interaction-D_CzyqRE.cjs';
|
|
3
4
|
import 'viem';
|
|
4
5
|
import 'viem/chains';
|
|
6
|
+
import 'viem/siwe';
|
|
5
7
|
|
|
6
8
|
/**
|
|
7
9
|
* Function used to watch the current nexus wallet status
|
|
@@ -27,4 +29,30 @@ declare function decodeStartUnlockReturn({ result, hash, }: {
|
|
|
27
29
|
validationHash: string;
|
|
28
30
|
}>>;
|
|
29
31
|
|
|
30
|
-
|
|
32
|
+
/**
|
|
33
|
+
* Function used to send a user transaction
|
|
34
|
+
* @param client
|
|
35
|
+
* @param tx
|
|
36
|
+
* @param context
|
|
37
|
+
* @param callback
|
|
38
|
+
*/
|
|
39
|
+
declare function sendTransaction(client: NexusClient, { tx, context }: SendTransactionActionParamsType): Promise<SendTransactionReturnType>;
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Function used to launch a siwe authentication
|
|
43
|
+
* @param client
|
|
44
|
+
* @param siwe
|
|
45
|
+
* @param context
|
|
46
|
+
*/
|
|
47
|
+
declare function siweAuthenticate(client: NexusClient, { siwe, context }: SiweAuthenticateActionParamsType): Promise<SiweAuthenticateReturnType>;
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Function used to send an interaction
|
|
51
|
+
* @param client
|
|
52
|
+
* @param contentId
|
|
53
|
+
* @param request
|
|
54
|
+
* @param validation
|
|
55
|
+
*/
|
|
56
|
+
declare function sendInteraction(client: NexusClient, { contentId, interaction, validation }: SendInteractionParamsType): Promise<SendInteractionReturnType>;
|
|
57
|
+
|
|
58
|
+
export { decodeStartUnlockReturn, getStartArticleUnlockUrl, sendInteraction, sendTransaction, siweAuthenticate, watchWalletStatus };
|