@frak-labs/nexus-sdk 0.0.13 → 0.0.15
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/README.md +4 -4
- package/dist/NexusContext-CSlCNW-G.d.cts +10 -0
- package/dist/NexusContext-CSlCNW-G.d.ts +10 -0
- package/dist/bundle/bundle.js +21 -0
- package/dist/chunk-2LAGZ6S5.js +246 -0
- package/dist/chunk-4ADWI2GG.cjs +243 -0
- package/dist/chunk-4LT3U3H4.cjs +246 -0
- package/dist/{chunk-FF32LTPI.js → chunk-ARQTOP44.js} +13 -197
- package/dist/chunk-C25NTD45.cjs +100 -0
- package/dist/chunk-DILTMQBI.cjs +51 -0
- package/dist/chunk-I47XQDS3.js +100 -0
- package/dist/chunk-K4FOGADW.js +51 -0
- package/dist/chunk-KEATMEOW.cjs +207 -0
- package/dist/chunk-VMNURFPI.js +207 -0
- package/dist/{client-B6_BIGc3.d.ts → client-B3Guoe3I.d.ts} +13 -7
- package/dist/{client-Oily5ph8.d.cts → client-Of9uIxuI.d.cts} +13 -7
- package/dist/core/actions/index.cjs +11 -3
- package/dist/core/actions/index.d.cts +33 -9
- package/dist/core/actions/index.d.ts +33 -9
- package/dist/core/actions/index.js +10 -2
- package/dist/core/index.cjs +14 -3
- package/dist/core/index.d.cts +84 -5
- package/dist/core/index.d.ts +84 -5
- package/dist/core/index.js +15 -4
- package/dist/core/interactions/index.cjs +3 -5
- package/dist/core/interactions/index.d.cts +20 -16
- package/dist/core/interactions/index.d.ts +20 -16
- package/dist/core/interactions/index.js +4 -6
- package/dist/{error-C4Zm5nQe.d.cts → error-Dflr3G5x.d.cts} +1 -1
- package/dist/{error-C4Zm5nQe.d.ts → error-Dflr3G5x.d.ts} +1 -1
- package/dist/{interaction-D3-M3nBh.d.ts → interaction-BngPoHA0.d.cts} +1 -1
- package/dist/{interaction-D3-M3nBh.d.cts → interaction-BngPoHA0.d.ts} +1 -1
- package/dist/react/index.cjs +75 -150
- package/dist/react/index.d.cts +8 -9
- package/dist/react/index.d.ts +8 -9
- package/dist/react/index.js +73 -148
- package/dist/{sendTransaction-BHqCq_9X.d.ts → sendTransaction-3d8jO9CJ.d.ts} +1 -1
- package/dist/{sendTransaction-BKKYEt8p.d.cts → sendTransaction-Cz6FoB9_.d.cts} +1 -1
- package/package.json +5 -5
- package/dist/chunk-2SGRLI7T.cjs +0 -427
- package/dist/chunk-5CFD5FM2.js +0 -86
- package/dist/chunk-ETV4XYOV.cjs +0 -7
- package/dist/chunk-GUDT2W6I.js +0 -70
- package/dist/chunk-IQQTTKJL.cjs +0 -70
- package/dist/chunk-PKBMQBKP.js +0 -7
- package/dist/chunk-S5FVCA2E.cjs +0 -86
- package/dist/index.cjs +0 -1
- package/dist/index.d.cts +0 -2
- package/dist/index.d.ts +0 -2
- package/dist/index.js +0 -0
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import {
|
|
2
|
+
interactionTypes,
|
|
3
|
+
productTypes
|
|
4
|
+
} from "./chunk-K4FOGADW.js";
|
|
5
|
+
|
|
6
|
+
// src/core/interactions/pressEncoder.ts
|
|
7
|
+
import { concatHex, pad, toHex } from "viem";
|
|
8
|
+
function openArticle({ articleId }) {
|
|
9
|
+
const interactionData = concatHex([
|
|
10
|
+
interactionTypes.press.openArticle,
|
|
11
|
+
pad(articleId, { size: 32 })
|
|
12
|
+
]);
|
|
13
|
+
return {
|
|
14
|
+
handlerTypeDenominator: toHex(productTypes.press),
|
|
15
|
+
interactionData
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
function readArticle({ articleId }) {
|
|
19
|
+
const interactionData = concatHex([
|
|
20
|
+
interactionTypes.press.readArticle,
|
|
21
|
+
pad(articleId, { size: 32 })
|
|
22
|
+
]);
|
|
23
|
+
return {
|
|
24
|
+
handlerTypeDenominator: toHex(productTypes.press),
|
|
25
|
+
interactionData
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
var PressInteractionEncoder = {
|
|
29
|
+
openArticle,
|
|
30
|
+
readArticle
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
// src/core/interactions/referralEncoder.ts
|
|
34
|
+
import { concatHex as concatHex2, pad as pad2, toHex as toHex2 } from "viem";
|
|
35
|
+
function createLink() {
|
|
36
|
+
const interactionData = concatHex2([
|
|
37
|
+
interactionTypes.referral.createLink,
|
|
38
|
+
"0x"
|
|
39
|
+
]);
|
|
40
|
+
return {
|
|
41
|
+
handlerTypeDenominator: toHex2(productTypes.referral),
|
|
42
|
+
interactionData
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
function referred({ referrer }) {
|
|
46
|
+
const interactionData = concatHex2([
|
|
47
|
+
interactionTypes.referral.referred,
|
|
48
|
+
pad2(referrer, { size: 32 })
|
|
49
|
+
]);
|
|
50
|
+
return {
|
|
51
|
+
handlerTypeDenominator: toHex2(productTypes.referral),
|
|
52
|
+
interactionData
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
var ReferralInteractionEncoder = {
|
|
56
|
+
createLink,
|
|
57
|
+
referred
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
// src/core/interactions/purchaseEncoder.ts
|
|
61
|
+
import { concatHex as concatHex3, encodeAbiParameters, pad as pad3, toHex as toHex3 } from "viem";
|
|
62
|
+
function startPurchase({
|
|
63
|
+
purchaseId
|
|
64
|
+
}) {
|
|
65
|
+
const interactionData = concatHex3([
|
|
66
|
+
interactionTypes.purchase.started,
|
|
67
|
+
pad3(purchaseId, { size: 32 })
|
|
68
|
+
]);
|
|
69
|
+
return {
|
|
70
|
+
handlerTypeDenominator: toHex3(productTypes.purchase),
|
|
71
|
+
interactionData
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
function completedPurchase({
|
|
75
|
+
purchaseId,
|
|
76
|
+
proof
|
|
77
|
+
}) {
|
|
78
|
+
const innerData = encodeAbiParameters(
|
|
79
|
+
[{ type: "uint256" }, { type: "bytes32[]" }],
|
|
80
|
+
[BigInt(purchaseId), proof]
|
|
81
|
+
);
|
|
82
|
+
const interactionData = concatHex3([
|
|
83
|
+
interactionTypes.purchase.completed,
|
|
84
|
+
innerData
|
|
85
|
+
]);
|
|
86
|
+
return {
|
|
87
|
+
handlerTypeDenominator: toHex3(productTypes.purchase),
|
|
88
|
+
interactionData
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
var PurchaseInteractionEncoder = {
|
|
92
|
+
startPurchase,
|
|
93
|
+
completedPurchase
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
export {
|
|
97
|
+
PressInteractionEncoder,
|
|
98
|
+
ReferralInteractionEncoder,
|
|
99
|
+
PurchaseInteractionEncoder
|
|
100
|
+
};
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
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) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
4
|
+
|
|
5
|
+
// src/core/constants/productTypes.ts
|
|
6
|
+
var productTypes = {
|
|
7
|
+
// content type
|
|
8
|
+
dapp: 1,
|
|
9
|
+
press: 2,
|
|
10
|
+
webshop: 3,
|
|
11
|
+
// feature type
|
|
12
|
+
referral: 30,
|
|
13
|
+
purchase: 31
|
|
14
|
+
};
|
|
15
|
+
var productTypesMask = Object.entries(
|
|
16
|
+
productTypes
|
|
17
|
+
).reduce(
|
|
18
|
+
(acc, [key, value]) => {
|
|
19
|
+
acc[key] = BigInt(1) << BigInt(value);
|
|
20
|
+
return acc;
|
|
21
|
+
},
|
|
22
|
+
{}
|
|
23
|
+
);
|
|
24
|
+
|
|
25
|
+
// src/core/constants/interactionTypes.ts
|
|
26
|
+
var interactionTypes = {
|
|
27
|
+
press: {
|
|
28
|
+
openArticle: "0xc0a24ffb",
|
|
29
|
+
readArticle: "0xd5bd0fbe"
|
|
30
|
+
},
|
|
31
|
+
dapp: {
|
|
32
|
+
proofVerifiableStorageUpdate: "0x2ab2aeef",
|
|
33
|
+
callableVerifiableStorageUpdate: "0xa07da986"
|
|
34
|
+
},
|
|
35
|
+
webshop: {},
|
|
36
|
+
referral: {
|
|
37
|
+
referred: "0x010cc3b9",
|
|
38
|
+
createLink: "0xb2c0f17c"
|
|
39
|
+
},
|
|
40
|
+
purchase: {
|
|
41
|
+
started: "0xd87e90c3",
|
|
42
|
+
completed: "0x8403aeb4"
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
export {
|
|
47
|
+
__publicField,
|
|
48
|
+
productTypes,
|
|
49
|
+
productTypesMask,
|
|
50
|
+
interactionTypes
|
|
51
|
+
};
|
|
@@ -0,0 +1,207 @@
|
|
|
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; }
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
var _chunk4LT3U3H4cjs = require('./chunk-4LT3U3H4.cjs');
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
var _chunkC25NTD45cjs = require('./chunk-C25NTD45.cjs');
|
|
10
|
+
|
|
11
|
+
// src/core/actions/watchWalletStatus.ts
|
|
12
|
+
function watchWalletStatus(client, callback) {
|
|
13
|
+
return client.listenerRequest(
|
|
14
|
+
{
|
|
15
|
+
method: "frak_listenToWalletStatus"
|
|
16
|
+
},
|
|
17
|
+
callback
|
|
18
|
+
);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
// src/core/utils/computeProductId.ts
|
|
22
|
+
var _viem = require('viem');
|
|
23
|
+
function computeProductId({ domain }) {
|
|
24
|
+
return _viem.keccak256.call(void 0, _viem.toHex.call(void 0, domain));
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// src/core/actions/sendInteraction.ts
|
|
28
|
+
async function sendInteraction(client, { productId, interaction, validation }) {
|
|
29
|
+
const pId = _nullishCoalesce(productId, () => ( computeProductId(client.config)));
|
|
30
|
+
return await client.request({
|
|
31
|
+
method: "frak_sendInteraction",
|
|
32
|
+
params: [pId, interaction, validation]
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// src/core/actions/displayModal.ts
|
|
37
|
+
async function displayModal(client, { steps, metadata }) {
|
|
38
|
+
return await client.request({
|
|
39
|
+
method: "frak_displayModal",
|
|
40
|
+
params: [steps, client.config.metadata.name, metadata]
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// src/core/actions/openSso.ts
|
|
45
|
+
async function openSso(client, args) {
|
|
46
|
+
const { metadata } = client.config;
|
|
47
|
+
await client.request({
|
|
48
|
+
method: "frak_sso",
|
|
49
|
+
params: [args, metadata.name, metadata.css]
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// src/core/actions/wrapper/siweAuthenticate.ts
|
|
54
|
+
var _siwe = require('viem/siwe');
|
|
55
|
+
async function siweAuthenticate(client, { siwe, metadata }) {
|
|
56
|
+
const realStatement = _nullishCoalesce(_optionalChain([siwe, 'optionalAccess', _ => _.statement]), () => ( `I confirm that I want to use my Frak wallet on: ${client.config.metadata.name}`));
|
|
57
|
+
const builtSiwe = {
|
|
58
|
+
...siwe,
|
|
59
|
+
statement: realStatement,
|
|
60
|
+
nonce: _nullishCoalesce(_optionalChain([siwe, 'optionalAccess', _2 => _2.nonce]), () => ( _siwe.generateSiweNonce.call(void 0, ))),
|
|
61
|
+
uri: _nullishCoalesce(_optionalChain([siwe, 'optionalAccess', _3 => _3.uri]), () => ( `https://${client.config.domain}`)),
|
|
62
|
+
version: _nullishCoalesce(_optionalChain([siwe, 'optionalAccess', _4 => _4.version]), () => ( "1")),
|
|
63
|
+
domain: client.config.domain
|
|
64
|
+
};
|
|
65
|
+
const result = await displayModal(client, {
|
|
66
|
+
metadata,
|
|
67
|
+
steps: {
|
|
68
|
+
login: {},
|
|
69
|
+
siweAuthenticate: {
|
|
70
|
+
siwe: builtSiwe
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
return result.siweAuthenticate;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
// src/core/actions/wrapper/sendTransaction.ts
|
|
78
|
+
async function sendTransaction(client, { tx, metadata }) {
|
|
79
|
+
const result = await displayModal(client, {
|
|
80
|
+
metadata,
|
|
81
|
+
steps: {
|
|
82
|
+
login: {},
|
|
83
|
+
sendTransaction: { tx }
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
return result.sendTransaction;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
// src/core/actions/wrapper/walletStatus.ts
|
|
90
|
+
async function walletStatus(client, callback) {
|
|
91
|
+
const firstResult = new (0, _chunk4LT3U3H4cjs.Deferred)();
|
|
92
|
+
let hasResolved = false;
|
|
93
|
+
await watchWalletStatus(client, (status) => {
|
|
94
|
+
_optionalChain([callback, 'optionalCall', _5 => _5(status)]);
|
|
95
|
+
if (!hasResolved) {
|
|
96
|
+
firstResult.resolve(status);
|
|
97
|
+
hasResolved = true;
|
|
98
|
+
}
|
|
99
|
+
});
|
|
100
|
+
return firstResult.promise;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
// src/core/actions/referral/processReferral.ts
|
|
104
|
+
|
|
105
|
+
async function processReferral(client, {
|
|
106
|
+
walletStatus: walletStatus2,
|
|
107
|
+
nexusContext,
|
|
108
|
+
modalConfig,
|
|
109
|
+
productId
|
|
110
|
+
}) {
|
|
111
|
+
try {
|
|
112
|
+
let currentWallet = getCurrentWallet(walletStatus2);
|
|
113
|
+
if (!_optionalChain([nexusContext, 'optionalAccess', _6 => _6.r])) {
|
|
114
|
+
if (currentWallet) {
|
|
115
|
+
await _chunk4LT3U3H4cjs.NexusContextManager.replaceUrl({
|
|
116
|
+
url: _optionalChain([window, 'access', _7 => _7.location, 'optionalAccess', _8 => _8.href]),
|
|
117
|
+
context: { r: currentWallet }
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
return "no-referrer";
|
|
121
|
+
}
|
|
122
|
+
if (!currentWallet) {
|
|
123
|
+
currentWallet = await ensureWalletConnected(client, {
|
|
124
|
+
modalConfig,
|
|
125
|
+
walletStatus: walletStatus2
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
if (currentWallet && _viem.isAddressEqual.call(void 0, nexusContext.r, currentWallet)) {
|
|
129
|
+
return "self-referral";
|
|
130
|
+
}
|
|
131
|
+
if (currentWallet) {
|
|
132
|
+
await _chunk4LT3U3H4cjs.NexusContextManager.replaceUrl({
|
|
133
|
+
url: _optionalChain([window, 'access', _9 => _9.location, 'optionalAccess', _10 => _10.href]),
|
|
134
|
+
context: { r: currentWallet }
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
const interaction = _chunkC25NTD45cjs.ReferralInteractionEncoder.referred({
|
|
138
|
+
referrer: nexusContext.r
|
|
139
|
+
});
|
|
140
|
+
await sendInteraction(client, { productId, interaction });
|
|
141
|
+
return "success";
|
|
142
|
+
} catch (error) {
|
|
143
|
+
return mapErrorToState(error);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
function getCurrentWallet(walletStatus2) {
|
|
147
|
+
return _optionalChain([walletStatus2, 'optionalAccess', _11 => _11.key]) === "connected" ? walletStatus2.wallet : void 0;
|
|
148
|
+
}
|
|
149
|
+
async function ensureWalletConnected(client, {
|
|
150
|
+
modalConfig,
|
|
151
|
+
walletStatus: walletStatus2
|
|
152
|
+
}) {
|
|
153
|
+
if (_optionalChain([walletStatus2, 'optionalAccess', _12 => _12.key]) !== "connected" || !walletStatus2.interactionSession) {
|
|
154
|
+
if (!modalConfig) {
|
|
155
|
+
return void 0;
|
|
156
|
+
}
|
|
157
|
+
const result = await displayModal(client, modalConfig);
|
|
158
|
+
return _nullishCoalesce(_optionalChain([result, 'optionalAccess', _13 => _13.login, 'optionalAccess', _14 => _14.wallet]), () => ( void 0));
|
|
159
|
+
}
|
|
160
|
+
return _nullishCoalesce(walletStatus2.wallet, () => ( void 0));
|
|
161
|
+
}
|
|
162
|
+
function mapErrorToState(error) {
|
|
163
|
+
if (error instanceof _chunk4LT3U3H4cjs.FrakRpcError) {
|
|
164
|
+
switch (error.code) {
|
|
165
|
+
case _chunk4LT3U3H4cjs.RpcErrorCodes.walletNotConnected:
|
|
166
|
+
return "no-wallet";
|
|
167
|
+
case _chunk4LT3U3H4cjs.RpcErrorCodes.serverErrorForInteractionDelegation:
|
|
168
|
+
return "no-session";
|
|
169
|
+
default:
|
|
170
|
+
return "error";
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
return "error";
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
// src/core/actions/referral/referralInteraction.ts
|
|
177
|
+
async function referralInteraction(client, {
|
|
178
|
+
productId,
|
|
179
|
+
modalConfig
|
|
180
|
+
} = {}) {
|
|
181
|
+
const nexusContext = await _chunk4LT3U3H4cjs.NexusContextManager.parse({
|
|
182
|
+
url: window.location.href
|
|
183
|
+
});
|
|
184
|
+
const currentWalletStatus = await walletStatus(client);
|
|
185
|
+
try {
|
|
186
|
+
return await processReferral(client, {
|
|
187
|
+
walletStatus: currentWalletStatus,
|
|
188
|
+
nexusContext,
|
|
189
|
+
modalConfig,
|
|
190
|
+
productId
|
|
191
|
+
});
|
|
192
|
+
} catch (error) {
|
|
193
|
+
return error;
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
|
|
198
|
+
|
|
199
|
+
|
|
200
|
+
|
|
201
|
+
|
|
202
|
+
|
|
203
|
+
|
|
204
|
+
|
|
205
|
+
|
|
206
|
+
|
|
207
|
+
exports.watchWalletStatus = watchWalletStatus; exports.sendInteraction = sendInteraction; exports.displayModal = displayModal; exports.openSso = openSso; exports.siweAuthenticate = siweAuthenticate; exports.sendTransaction = sendTransaction; exports.walletStatus = walletStatus; exports.processReferral = processReferral; exports.referralInteraction = referralInteraction;
|
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Deferred,
|
|
3
|
+
FrakRpcError,
|
|
4
|
+
NexusContextManager,
|
|
5
|
+
RpcErrorCodes
|
|
6
|
+
} from "./chunk-2LAGZ6S5.js";
|
|
7
|
+
import {
|
|
8
|
+
ReferralInteractionEncoder
|
|
9
|
+
} from "./chunk-I47XQDS3.js";
|
|
10
|
+
|
|
11
|
+
// src/core/actions/watchWalletStatus.ts
|
|
12
|
+
function watchWalletStatus(client, callback) {
|
|
13
|
+
return client.listenerRequest(
|
|
14
|
+
{
|
|
15
|
+
method: "frak_listenToWalletStatus"
|
|
16
|
+
},
|
|
17
|
+
callback
|
|
18
|
+
);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
// src/core/utils/computeProductId.ts
|
|
22
|
+
import { keccak256, toHex } from "viem";
|
|
23
|
+
function computeProductId({ domain }) {
|
|
24
|
+
return keccak256(toHex(domain));
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// src/core/actions/sendInteraction.ts
|
|
28
|
+
async function sendInteraction(client, { productId, interaction, validation }) {
|
|
29
|
+
const pId = productId ?? computeProductId(client.config);
|
|
30
|
+
return await client.request({
|
|
31
|
+
method: "frak_sendInteraction",
|
|
32
|
+
params: [pId, interaction, validation]
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// src/core/actions/displayModal.ts
|
|
37
|
+
async function displayModal(client, { steps, metadata }) {
|
|
38
|
+
return await client.request({
|
|
39
|
+
method: "frak_displayModal",
|
|
40
|
+
params: [steps, client.config.metadata.name, metadata]
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// src/core/actions/openSso.ts
|
|
45
|
+
async function openSso(client, args) {
|
|
46
|
+
const { metadata } = client.config;
|
|
47
|
+
await client.request({
|
|
48
|
+
method: "frak_sso",
|
|
49
|
+
params: [args, metadata.name, metadata.css]
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// src/core/actions/wrapper/siweAuthenticate.ts
|
|
54
|
+
import { generateSiweNonce } from "viem/siwe";
|
|
55
|
+
async function siweAuthenticate(client, { siwe, metadata }) {
|
|
56
|
+
const realStatement = siwe?.statement ?? `I confirm that I want to use my Frak wallet on: ${client.config.metadata.name}`;
|
|
57
|
+
const builtSiwe = {
|
|
58
|
+
...siwe,
|
|
59
|
+
statement: realStatement,
|
|
60
|
+
nonce: siwe?.nonce ?? generateSiweNonce(),
|
|
61
|
+
uri: siwe?.uri ?? `https://${client.config.domain}`,
|
|
62
|
+
version: siwe?.version ?? "1",
|
|
63
|
+
domain: client.config.domain
|
|
64
|
+
};
|
|
65
|
+
const result = await displayModal(client, {
|
|
66
|
+
metadata,
|
|
67
|
+
steps: {
|
|
68
|
+
login: {},
|
|
69
|
+
siweAuthenticate: {
|
|
70
|
+
siwe: builtSiwe
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
return result.siweAuthenticate;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
// src/core/actions/wrapper/sendTransaction.ts
|
|
78
|
+
async function sendTransaction(client, { tx, metadata }) {
|
|
79
|
+
const result = await displayModal(client, {
|
|
80
|
+
metadata,
|
|
81
|
+
steps: {
|
|
82
|
+
login: {},
|
|
83
|
+
sendTransaction: { tx }
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
return result.sendTransaction;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
// src/core/actions/wrapper/walletStatus.ts
|
|
90
|
+
async function walletStatus(client, callback) {
|
|
91
|
+
const firstResult = new Deferred();
|
|
92
|
+
let hasResolved = false;
|
|
93
|
+
await watchWalletStatus(client, (status) => {
|
|
94
|
+
callback?.(status);
|
|
95
|
+
if (!hasResolved) {
|
|
96
|
+
firstResult.resolve(status);
|
|
97
|
+
hasResolved = true;
|
|
98
|
+
}
|
|
99
|
+
});
|
|
100
|
+
return firstResult.promise;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
// src/core/actions/referral/processReferral.ts
|
|
104
|
+
import { isAddressEqual } from "viem";
|
|
105
|
+
async function processReferral(client, {
|
|
106
|
+
walletStatus: walletStatus2,
|
|
107
|
+
nexusContext,
|
|
108
|
+
modalConfig,
|
|
109
|
+
productId
|
|
110
|
+
}) {
|
|
111
|
+
try {
|
|
112
|
+
let currentWallet = getCurrentWallet(walletStatus2);
|
|
113
|
+
if (!nexusContext?.r) {
|
|
114
|
+
if (currentWallet) {
|
|
115
|
+
await NexusContextManager.replaceUrl({
|
|
116
|
+
url: window.location?.href,
|
|
117
|
+
context: { r: currentWallet }
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
return "no-referrer";
|
|
121
|
+
}
|
|
122
|
+
if (!currentWallet) {
|
|
123
|
+
currentWallet = await ensureWalletConnected(client, {
|
|
124
|
+
modalConfig,
|
|
125
|
+
walletStatus: walletStatus2
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
if (currentWallet && isAddressEqual(nexusContext.r, currentWallet)) {
|
|
129
|
+
return "self-referral";
|
|
130
|
+
}
|
|
131
|
+
if (currentWallet) {
|
|
132
|
+
await NexusContextManager.replaceUrl({
|
|
133
|
+
url: window.location?.href,
|
|
134
|
+
context: { r: currentWallet }
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
const interaction = ReferralInteractionEncoder.referred({
|
|
138
|
+
referrer: nexusContext.r
|
|
139
|
+
});
|
|
140
|
+
await sendInteraction(client, { productId, interaction });
|
|
141
|
+
return "success";
|
|
142
|
+
} catch (error) {
|
|
143
|
+
return mapErrorToState(error);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
function getCurrentWallet(walletStatus2) {
|
|
147
|
+
return walletStatus2?.key === "connected" ? walletStatus2.wallet : void 0;
|
|
148
|
+
}
|
|
149
|
+
async function ensureWalletConnected(client, {
|
|
150
|
+
modalConfig,
|
|
151
|
+
walletStatus: walletStatus2
|
|
152
|
+
}) {
|
|
153
|
+
if (walletStatus2?.key !== "connected" || !walletStatus2.interactionSession) {
|
|
154
|
+
if (!modalConfig) {
|
|
155
|
+
return void 0;
|
|
156
|
+
}
|
|
157
|
+
const result = await displayModal(client, modalConfig);
|
|
158
|
+
return result?.login?.wallet ?? void 0;
|
|
159
|
+
}
|
|
160
|
+
return walletStatus2.wallet ?? void 0;
|
|
161
|
+
}
|
|
162
|
+
function mapErrorToState(error) {
|
|
163
|
+
if (error instanceof FrakRpcError) {
|
|
164
|
+
switch (error.code) {
|
|
165
|
+
case RpcErrorCodes.walletNotConnected:
|
|
166
|
+
return "no-wallet";
|
|
167
|
+
case RpcErrorCodes.serverErrorForInteractionDelegation:
|
|
168
|
+
return "no-session";
|
|
169
|
+
default:
|
|
170
|
+
return "error";
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
return "error";
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
// src/core/actions/referral/referralInteraction.ts
|
|
177
|
+
async function referralInteraction(client, {
|
|
178
|
+
productId,
|
|
179
|
+
modalConfig
|
|
180
|
+
} = {}) {
|
|
181
|
+
const nexusContext = await NexusContextManager.parse({
|
|
182
|
+
url: window.location.href
|
|
183
|
+
});
|
|
184
|
+
const currentWalletStatus = await walletStatus(client);
|
|
185
|
+
try {
|
|
186
|
+
return await processReferral(client, {
|
|
187
|
+
walletStatus: currentWalletStatus,
|
|
188
|
+
nexusContext,
|
|
189
|
+
modalConfig,
|
|
190
|
+
productId
|
|
191
|
+
});
|
|
192
|
+
} catch (error) {
|
|
193
|
+
return error;
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
export {
|
|
198
|
+
watchWalletStatus,
|
|
199
|
+
sendInteraction,
|
|
200
|
+
displayModal,
|
|
201
|
+
openSso,
|
|
202
|
+
siweAuthenticate,
|
|
203
|
+
sendTransaction,
|
|
204
|
+
walletStatus,
|
|
205
|
+
processReferral,
|
|
206
|
+
referralInteraction
|
|
207
|
+
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Address, Hex, RpcSchema } from 'viem';
|
|
2
2
|
import { Prettify } from 'viem/chains';
|
|
3
3
|
import { SiweMessage } from 'viem/siwe';
|
|
4
|
-
import { P as PreparedInteraction, a as SendInteractionReturnType } from './interaction-
|
|
4
|
+
import { P as PreparedInteraction, a as SendInteractionReturnType } from './interaction-BngPoHA0.js';
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* Configuration for the Nexus Wallet SDK
|
|
@@ -21,13 +21,16 @@ type NexusWalletSdkConfig = Readonly<{
|
|
|
21
21
|
type IFrameLifecycleEvent = {
|
|
22
22
|
iframeLifecycle: "connected" | "show" | "hide";
|
|
23
23
|
data?: never;
|
|
24
|
-
} | DoBackupEvent;
|
|
24
|
+
} | DoBackupEvent | RemoveBackupEvent;
|
|
25
25
|
type DoBackupEvent = {
|
|
26
26
|
iframeLifecycle: "do-backup";
|
|
27
27
|
data: {
|
|
28
28
|
backup?: string;
|
|
29
29
|
};
|
|
30
30
|
};
|
|
31
|
+
type RemoveBackupEvent = {
|
|
32
|
+
iframeLifecycle: "remove-backup";
|
|
33
|
+
};
|
|
31
34
|
|
|
32
35
|
/**
|
|
33
36
|
* Event related to the iframe lifecycle
|
|
@@ -50,8 +53,8 @@ type RestoreBackupEvent = {
|
|
|
50
53
|
* SSO Metadata
|
|
51
54
|
*/
|
|
52
55
|
type SsoMetadata = {
|
|
53
|
-
logoUrl
|
|
54
|
-
homepageLink
|
|
56
|
+
logoUrl?: string;
|
|
57
|
+
homepageLink?: string;
|
|
55
58
|
links?: {
|
|
56
59
|
confidentialityLink?: string;
|
|
57
60
|
helpLink?: string;
|
|
@@ -102,7 +105,10 @@ type LoginModalStepType = GenericModalStepType<"login", LoginWithSso | LoginWith
|
|
|
102
105
|
/**
|
|
103
106
|
* Parameters of the send transaction rpc request
|
|
104
107
|
*/
|
|
105
|
-
type SiweAuthenticationParams = Omit<SiweMessage, "address" | "chainId"
|
|
108
|
+
type SiweAuthenticationParams = Omit<SiweMessage, "address" | "chainId" | "expirationTime" | "issuedAt" | "notBefore"> & {
|
|
109
|
+
expirationTimeTimestamp?: number;
|
|
110
|
+
notBeforeTimestamp?: number;
|
|
111
|
+
};
|
|
106
112
|
/**
|
|
107
113
|
* Return type of the send transaction rpc request
|
|
108
114
|
*/
|
|
@@ -240,7 +246,7 @@ type IFrameRpcSchema = [
|
|
|
240
246
|
{
|
|
241
247
|
Method: "frak_sendInteraction";
|
|
242
248
|
Parameters: [
|
|
243
|
-
|
|
249
|
+
productId: Hex,
|
|
244
250
|
interaction: PreparedInteraction,
|
|
245
251
|
signature?: Hex
|
|
246
252
|
];
|
|
@@ -354,4 +360,4 @@ type NexusClient = {
|
|
|
354
360
|
config: NexusWalletSdkConfig;
|
|
355
361
|
} & IFrameTransport;
|
|
356
362
|
|
|
357
|
-
export type { ClientLifecycleEvent as C, DisplayModalParamsType as D, ExtractedParametersFromRpc as E, IFrameRpcSchema as I, LoginModalStepType as L,
|
|
363
|
+
export type { ClientLifecycleEvent as C, DisplayModalParamsType as D, ExtractedParametersFromRpc as E, IFrameRpcSchema as I, LoginModalStepType as L, ModalStepTypes as M, NexusWalletSdkConfig as N, OpenSsoParamsType as O, RpcResponse as R, SuccessModalStepType as S, WalletStatusReturnType as W, NexusClient as a, SsoMetadata as b, ModalRpcMetadata as c, ModalRpcStepsInput as d, ModalRpcStepsResultType as e, ModalStepMetadata as f, SiweAuthenticateModalStepType as g, SiweAuthenticationParams as h, SiweAuthenticateReturnType as i, SendTransactionTxType as j, SendTransactionModalStepType as k, SendTransactionReturnType as l, OpenInteractionSessionReturnType as m, OpenInteractionSessionModalStepType as n, IFrameTransport as o, IFrameRpcEvent as p, IFrameEvent as q, IFrameLifecycleEvent as r, ExtractedReturnTypeFromRpc as s };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Address, Hex, RpcSchema } from 'viem';
|
|
2
2
|
import { Prettify } from 'viem/chains';
|
|
3
3
|
import { SiweMessage } from 'viem/siwe';
|
|
4
|
-
import { P as PreparedInteraction, a as SendInteractionReturnType } from './interaction-
|
|
4
|
+
import { P as PreparedInteraction, a as SendInteractionReturnType } from './interaction-BngPoHA0.cjs';
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* Configuration for the Nexus Wallet SDK
|
|
@@ -21,13 +21,16 @@ type NexusWalletSdkConfig = Readonly<{
|
|
|
21
21
|
type IFrameLifecycleEvent = {
|
|
22
22
|
iframeLifecycle: "connected" | "show" | "hide";
|
|
23
23
|
data?: never;
|
|
24
|
-
} | DoBackupEvent;
|
|
24
|
+
} | DoBackupEvent | RemoveBackupEvent;
|
|
25
25
|
type DoBackupEvent = {
|
|
26
26
|
iframeLifecycle: "do-backup";
|
|
27
27
|
data: {
|
|
28
28
|
backup?: string;
|
|
29
29
|
};
|
|
30
30
|
};
|
|
31
|
+
type RemoveBackupEvent = {
|
|
32
|
+
iframeLifecycle: "remove-backup";
|
|
33
|
+
};
|
|
31
34
|
|
|
32
35
|
/**
|
|
33
36
|
* Event related to the iframe lifecycle
|
|
@@ -50,8 +53,8 @@ type RestoreBackupEvent = {
|
|
|
50
53
|
* SSO Metadata
|
|
51
54
|
*/
|
|
52
55
|
type SsoMetadata = {
|
|
53
|
-
logoUrl
|
|
54
|
-
homepageLink
|
|
56
|
+
logoUrl?: string;
|
|
57
|
+
homepageLink?: string;
|
|
55
58
|
links?: {
|
|
56
59
|
confidentialityLink?: string;
|
|
57
60
|
helpLink?: string;
|
|
@@ -102,7 +105,10 @@ type LoginModalStepType = GenericModalStepType<"login", LoginWithSso | LoginWith
|
|
|
102
105
|
/**
|
|
103
106
|
* Parameters of the send transaction rpc request
|
|
104
107
|
*/
|
|
105
|
-
type SiweAuthenticationParams = Omit<SiweMessage, "address" | "chainId"
|
|
108
|
+
type SiweAuthenticationParams = Omit<SiweMessage, "address" | "chainId" | "expirationTime" | "issuedAt" | "notBefore"> & {
|
|
109
|
+
expirationTimeTimestamp?: number;
|
|
110
|
+
notBeforeTimestamp?: number;
|
|
111
|
+
};
|
|
106
112
|
/**
|
|
107
113
|
* Return type of the send transaction rpc request
|
|
108
114
|
*/
|
|
@@ -240,7 +246,7 @@ type IFrameRpcSchema = [
|
|
|
240
246
|
{
|
|
241
247
|
Method: "frak_sendInteraction";
|
|
242
248
|
Parameters: [
|
|
243
|
-
|
|
249
|
+
productId: Hex,
|
|
244
250
|
interaction: PreparedInteraction,
|
|
245
251
|
signature?: Hex
|
|
246
252
|
];
|
|
@@ -354,4 +360,4 @@ type NexusClient = {
|
|
|
354
360
|
config: NexusWalletSdkConfig;
|
|
355
361
|
} & IFrameTransport;
|
|
356
362
|
|
|
357
|
-
export type { ClientLifecycleEvent as C, DisplayModalParamsType as D, ExtractedParametersFromRpc as E, IFrameRpcSchema as I, LoginModalStepType as L,
|
|
363
|
+
export type { ClientLifecycleEvent as C, DisplayModalParamsType as D, ExtractedParametersFromRpc as E, IFrameRpcSchema as I, LoginModalStepType as L, ModalStepTypes as M, NexusWalletSdkConfig as N, OpenSsoParamsType as O, RpcResponse as R, SuccessModalStepType as S, WalletStatusReturnType as W, NexusClient as a, SsoMetadata as b, ModalRpcMetadata as c, ModalRpcStepsInput as d, ModalRpcStepsResultType as e, ModalStepMetadata as f, SiweAuthenticateModalStepType as g, SiweAuthenticationParams as h, SiweAuthenticateReturnType as i, SendTransactionTxType as j, SendTransactionModalStepType as k, SendTransactionReturnType as l, OpenInteractionSessionReturnType as m, OpenInteractionSessionModalStepType as n, IFrameTransport as o, IFrameRpcEvent as p, IFrameEvent as q, IFrameLifecycleEvent as r, ExtractedReturnTypeFromRpc as s };
|