@frak-labs/nexus-sdk 0.0.9 → 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-SZUN32YC.js → chunk-HOX3RRO6.js} +58 -30
- package/dist/chunk-NIFJZD3M.cjs +48 -0
- package/dist/chunk-PKBMQBKP.js +7 -0
- package/dist/{chunk-AYZHGMEV.cjs → chunk-SGLR6RFA.cjs} +59 -31
- package/dist/chunk-T54VMWHQ.js +100 -0
- package/dist/chunk-TPC5PMRC.js +152 -0
- package/dist/{client-BwzXSgqQ.d.ts → client--U_6SK0l.d.cts} +91 -30
- package/dist/{client-BwzXSgqQ.d.cts → client-6_BJp7Ub.d.ts} +91 -30
- package/dist/core/actions/index.cjs +8 -3
- package/dist/core/actions/index.d.cts +25 -13
- package/dist/core/actions/index.d.ts +25 -13
- package/dist/core/actions/index.js +9 -4
- 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 +234 -109
- package/dist/react/index.d.cts +69 -19
- package/dist/react/index.d.ts +69 -19
- package/dist/react/index.js +236 -111
- package/dist/{watchUnlockStatus-WJxoDliF.d.ts → watchUnlockStatus-CxnibdQx.d.cts} +3 -3
- package/dist/{watchUnlockStatus-DXClCYH9.d.cts → watchUnlockStatus-g8wIxpeM.d.ts} +3 -3
- package/package.json +11 -5
- package/dist/chunk-PDR3CF3P.js +0 -86
- package/dist/chunk-VK7GPKK4.js +0 -169
- package/dist/chunk-X4JNNWJ4.cjs +0 -86
- package/dist/chunk-ZOLP2FJZ.cjs +0 -169
|
@@ -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,27 +11,53 @@ type NexusWalletSdkConfig = Readonly<{
|
|
|
9
11
|
metadata: {
|
|
10
12
|
name: string;
|
|
11
13
|
};
|
|
14
|
+
domain: string;
|
|
12
15
|
}>;
|
|
13
16
|
|
|
14
17
|
/**
|
|
15
|
-
* Parameters of the
|
|
18
|
+
* Parameters of the send transaction rpc request
|
|
16
19
|
*/
|
|
17
|
-
type
|
|
18
|
-
|
|
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;
|
|
19
27
|
}>;
|
|
20
28
|
/**
|
|
21
|
-
* Return type of the
|
|
29
|
+
* Return type of the send transaction rpc request
|
|
22
30
|
*/
|
|
23
|
-
type
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
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
|
+
}>;
|
|
33
61
|
|
|
34
62
|
type PaidArticleUnlockPrice = Readonly<{
|
|
35
63
|
index: number;
|
|
@@ -172,12 +200,32 @@ type IFrameRpcSchema = [
|
|
|
172
200
|
ReturnType: ArticleUnlockStatusReturnType;
|
|
173
201
|
},
|
|
174
202
|
/**
|
|
175
|
-
* Method
|
|
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
|
|
176
220
|
*/
|
|
177
221
|
{
|
|
178
|
-
Method: "
|
|
179
|
-
Parameters: [
|
|
180
|
-
|
|
222
|
+
Method: "frak_sendInteraction";
|
|
223
|
+
Parameters: [
|
|
224
|
+
contentId: Hex,
|
|
225
|
+
interaction: PreparedInteraction,
|
|
226
|
+
signature?: Hex
|
|
227
|
+
];
|
|
228
|
+
ReturnType: SendInteractionReturnType;
|
|
181
229
|
}
|
|
182
230
|
];
|
|
183
231
|
/**
|
|
@@ -198,7 +246,7 @@ type RedirectRpcSchema = [
|
|
|
198
246
|
/**
|
|
199
247
|
* Type that extract the possible parameters from a RPC Schema
|
|
200
248
|
*/
|
|
201
|
-
type ExtractedParametersFromRpc<TRpcSchema extends RpcSchema
|
|
249
|
+
type ExtractedParametersFromRpc<TRpcSchema extends RpcSchema> = {
|
|
202
250
|
[K in keyof TRpcSchema]: Prettify<{
|
|
203
251
|
method: TRpcSchema[K] extends TRpcSchema[number] ? TRpcSchema[K]["Method"] : string;
|
|
204
252
|
} & (TRpcSchema[K] extends TRpcSchema[number] ? TRpcSchema[K]["Parameters"] extends undefined ? {
|
|
@@ -206,28 +254,41 @@ type ExtractedParametersFromRpc<TRpcSchema extends RpcSchema | undefined = undef
|
|
|
206
254
|
} : {
|
|
207
255
|
params: TRpcSchema[K]["Parameters"];
|
|
208
256
|
} : never)>;
|
|
209
|
-
}[number]
|
|
210
|
-
method: string;
|
|
211
|
-
params?: unknown;
|
|
212
|
-
};
|
|
257
|
+
}[number];
|
|
213
258
|
/**
|
|
214
259
|
* Type that extract the possible return type from a RPC Schema
|
|
215
260
|
*/
|
|
216
|
-
type ExtractedReturnTypeFromRpc<TRpcSchema extends RpcSchema
|
|
261
|
+
type ExtractedReturnTypeFromRpc<TRpcSchema extends RpcSchema, TParameters extends ExtractedParametersFromRpc<TRpcSchema> = ExtractedParametersFromRpc<TRpcSchema>> = ExtractedMethodFromRpc<TRpcSchema, TParameters["method"]>["ReturnType"];
|
|
217
262
|
/**
|
|
218
263
|
* Type that extract the possible return type from a RPC Schema
|
|
219
264
|
*/
|
|
220
|
-
type ExtractedMethodFromRpc<TRpcSchema extends RpcSchema
|
|
265
|
+
type ExtractedMethodFromRpc<TRpcSchema extends RpcSchema, TMethod extends ExtractedParametersFromRpc<TRpcSchema>["method"] = ExtractedParametersFromRpc<TRpcSchema>["method"]> = Extract<TRpcSchema[number], {
|
|
221
266
|
Method: TMethod;
|
|
222
|
-
}
|
|
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
|
+
};
|
|
223
284
|
/**
|
|
224
285
|
* Type used for a one shot request function
|
|
225
286
|
*/
|
|
226
|
-
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>;
|
|
227
288
|
/**
|
|
228
289
|
* Type used for a one shot request function
|
|
229
290
|
*/
|
|
230
|
-
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>;
|
|
231
292
|
/**
|
|
232
293
|
* IFrame transport interface
|
|
233
294
|
*/
|
|
@@ -265,7 +326,7 @@ type IFrameRpcEvent = {
|
|
|
265
326
|
};
|
|
266
327
|
};
|
|
267
328
|
type IFrameLifecycleEvent = {
|
|
268
|
-
lifecycle: "connected";
|
|
329
|
+
lifecycle: "connected" | "show" | "hide";
|
|
269
330
|
};
|
|
270
331
|
|
|
271
332
|
/**
|
|
@@ -275,4 +336,4 @@ type NexusClient = {
|
|
|
275
336
|
config: NexusWalletSdkConfig;
|
|
276
337
|
} & IFrameTransport;
|
|
277
338
|
|
|
278
|
-
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,27 +11,53 @@ type NexusWalletSdkConfig = Readonly<{
|
|
|
9
11
|
metadata: {
|
|
10
12
|
name: string;
|
|
11
13
|
};
|
|
14
|
+
domain: string;
|
|
12
15
|
}>;
|
|
13
16
|
|
|
14
17
|
/**
|
|
15
|
-
* Parameters of the
|
|
18
|
+
* Parameters of the send transaction rpc request
|
|
16
19
|
*/
|
|
17
|
-
type
|
|
18
|
-
|
|
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;
|
|
19
27
|
}>;
|
|
20
28
|
/**
|
|
21
|
-
* Return type of the
|
|
29
|
+
* Return type of the send transaction rpc request
|
|
22
30
|
*/
|
|
23
|
-
type
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
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
|
+
}>;
|
|
33
61
|
|
|
34
62
|
type PaidArticleUnlockPrice = Readonly<{
|
|
35
63
|
index: number;
|
|
@@ -172,12 +200,32 @@ type IFrameRpcSchema = [
|
|
|
172
200
|
ReturnType: ArticleUnlockStatusReturnType;
|
|
173
201
|
},
|
|
174
202
|
/**
|
|
175
|
-
* Method
|
|
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
|
|
176
220
|
*/
|
|
177
221
|
{
|
|
178
|
-
Method: "
|
|
179
|
-
Parameters: [
|
|
180
|
-
|
|
222
|
+
Method: "frak_sendInteraction";
|
|
223
|
+
Parameters: [
|
|
224
|
+
contentId: Hex,
|
|
225
|
+
interaction: PreparedInteraction,
|
|
226
|
+
signature?: Hex
|
|
227
|
+
];
|
|
228
|
+
ReturnType: SendInteractionReturnType;
|
|
181
229
|
}
|
|
182
230
|
];
|
|
183
231
|
/**
|
|
@@ -198,7 +246,7 @@ type RedirectRpcSchema = [
|
|
|
198
246
|
/**
|
|
199
247
|
* Type that extract the possible parameters from a RPC Schema
|
|
200
248
|
*/
|
|
201
|
-
type ExtractedParametersFromRpc<TRpcSchema extends RpcSchema
|
|
249
|
+
type ExtractedParametersFromRpc<TRpcSchema extends RpcSchema> = {
|
|
202
250
|
[K in keyof TRpcSchema]: Prettify<{
|
|
203
251
|
method: TRpcSchema[K] extends TRpcSchema[number] ? TRpcSchema[K]["Method"] : string;
|
|
204
252
|
} & (TRpcSchema[K] extends TRpcSchema[number] ? TRpcSchema[K]["Parameters"] extends undefined ? {
|
|
@@ -206,28 +254,41 @@ type ExtractedParametersFromRpc<TRpcSchema extends RpcSchema | undefined = undef
|
|
|
206
254
|
} : {
|
|
207
255
|
params: TRpcSchema[K]["Parameters"];
|
|
208
256
|
} : never)>;
|
|
209
|
-
}[number]
|
|
210
|
-
method: string;
|
|
211
|
-
params?: unknown;
|
|
212
|
-
};
|
|
257
|
+
}[number];
|
|
213
258
|
/**
|
|
214
259
|
* Type that extract the possible return type from a RPC Schema
|
|
215
260
|
*/
|
|
216
|
-
type ExtractedReturnTypeFromRpc<TRpcSchema extends RpcSchema
|
|
261
|
+
type ExtractedReturnTypeFromRpc<TRpcSchema extends RpcSchema, TParameters extends ExtractedParametersFromRpc<TRpcSchema> = ExtractedParametersFromRpc<TRpcSchema>> = ExtractedMethodFromRpc<TRpcSchema, TParameters["method"]>["ReturnType"];
|
|
217
262
|
/**
|
|
218
263
|
* Type that extract the possible return type from a RPC Schema
|
|
219
264
|
*/
|
|
220
|
-
type ExtractedMethodFromRpc<TRpcSchema extends RpcSchema
|
|
265
|
+
type ExtractedMethodFromRpc<TRpcSchema extends RpcSchema, TMethod extends ExtractedParametersFromRpc<TRpcSchema>["method"] = ExtractedParametersFromRpc<TRpcSchema>["method"]> = Extract<TRpcSchema[number], {
|
|
221
266
|
Method: TMethod;
|
|
222
|
-
}
|
|
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
|
+
};
|
|
223
284
|
/**
|
|
224
285
|
* Type used for a one shot request function
|
|
225
286
|
*/
|
|
226
|
-
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>;
|
|
227
288
|
/**
|
|
228
289
|
* Type used for a one shot request function
|
|
229
290
|
*/
|
|
230
|
-
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>;
|
|
231
292
|
/**
|
|
232
293
|
* IFrame transport interface
|
|
233
294
|
*/
|
|
@@ -265,7 +326,7 @@ type IFrameRpcEvent = {
|
|
|
265
326
|
};
|
|
266
327
|
};
|
|
267
328
|
type IFrameLifecycleEvent = {
|
|
268
|
-
lifecycle: "connected";
|
|
329
|
+
lifecycle: "connected" | "show" | "hide";
|
|
269
330
|
};
|
|
270
331
|
|
|
271
332
|
/**
|
|
@@ -275,4 +336,4 @@ type NexusClient = {
|
|
|
275
336
|
config: NexusWalletSdkConfig;
|
|
276
337
|
} & IFrameTransport;
|
|
277
338
|
|
|
278
|
-
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 };
|
|
@@ -5,13 +5,18 @@
|
|
|
5
5
|
|
|
6
6
|
|
|
7
7
|
|
|
8
|
-
var _chunkX4JNNWJ4cjs = require('../../chunk-X4JNNWJ4.cjs');
|
|
9
|
-
require('../../chunk-ZOLP2FJZ.cjs');
|
|
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
|
|
|
16
17
|
|
|
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;
|