@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/package.json
CHANGED
|
@@ -11,9 +11,12 @@
|
|
|
11
11
|
"url": "https://twitter.com/QNivelais"
|
|
12
12
|
}
|
|
13
13
|
],
|
|
14
|
-
"version": "0.0.
|
|
14
|
+
"version": "0.0.12",
|
|
15
15
|
"description": "Nexus Wallet client SDK, helping any person to interact with the Frak wallet, and require the unlock of a premium article within the Frak ecosystem.",
|
|
16
|
-
"repository":
|
|
16
|
+
"repository": {
|
|
17
|
+
"url": "https://github.com/frak-id/wallet",
|
|
18
|
+
"directory": "packages/sdk"
|
|
19
|
+
},
|
|
17
20
|
"homepage": "https://docs.frak.id/wallet-sdk",
|
|
18
21
|
"keywords": [
|
|
19
22
|
"frak-labs",
|
|
@@ -78,9 +81,9 @@
|
|
|
78
81
|
"js-sha256": "^0.11.0"
|
|
79
82
|
},
|
|
80
83
|
"devDependencies": {
|
|
81
|
-
"@tanstack/react-query": ">=5.
|
|
82
|
-
"@types/node": "^
|
|
83
|
-
"tsup": "^8.
|
|
84
|
+
"@tanstack/react-query": ">=5.51.15",
|
|
85
|
+
"@types/node": "^22",
|
|
86
|
+
"tsup": "^8.2.3",
|
|
84
87
|
"typescript": "^5"
|
|
85
88
|
}
|
|
86
89
|
}
|
package/dist/chunk-3T2FNW6E.cjs
DELETED
|
@@ -1,100 +0,0 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
var _chunkBPFJZRJ6cjs = require('./chunk-BPFJZRJ6.cjs');
|
|
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 _chunkBPFJZRJ6cjs.hashAndCompressData.call(void 0, {
|
|
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 _chunkBPFJZRJ6cjs.decompressDataAndCheckHash.call(void 0, {
|
|
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
|
-
var _siwe = require('viem/siwe');
|
|
67
|
-
async function siweAuthenticate(client, { siwe, context }) {
|
|
68
|
-
const realStatement = _nullishCoalesce(_optionalChain([siwe, 'optionalAccess', _ => _.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: _nullishCoalesce(_optionalChain([siwe, 'optionalAccess', _2 => _2.nonce]), () => ( _siwe.generateSiweNonce.call(void 0, ))),
|
|
73
|
-
uri: _nullishCoalesce(_optionalChain([siwe, 'optionalAccess', _3 => _3.uri]), () => ( `https://${client.config.domain}`)),
|
|
74
|
-
version: _nullishCoalesce(_optionalChain([siwe, 'optionalAccess', _4 => _4.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
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
exports.getArticleUnlockOptions = getArticleUnlockOptions; exports.watchUnlockStatus = watchUnlockStatus; exports.watchWalletStatus = watchWalletStatus; exports.getStartArticleUnlockUrl = getStartArticleUnlockUrl; exports.decodeStartUnlockReturn = decodeStartUnlockReturn; exports.sendTransaction = sendTransaction; exports.siweAuthenticate = siweAuthenticate; exports.sendInteraction = sendInteraction;
|
package/dist/chunk-BPFJZRJ6.cjs
DELETED
|
@@ -1,152 +0,0 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); 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; }// 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
|
-
var _asynclzstring = require('async-lz-string');
|
|
33
|
-
var _jssha256 = require('js-sha256');
|
|
34
|
-
async function hashAndCompressData(data) {
|
|
35
|
-
const validationHash = _jssha256.sha256.call(void 0, JSON.stringify(data));
|
|
36
|
-
const hashProtectedData = {
|
|
37
|
-
...data,
|
|
38
|
-
validationHash
|
|
39
|
-
};
|
|
40
|
-
const compressed = await compressJson(hashProtectedData);
|
|
41
|
-
const compressedHash = _jssha256.sha256.call(void 0, compressed);
|
|
42
|
-
return {
|
|
43
|
-
compressed,
|
|
44
|
-
compressedHash
|
|
45
|
-
};
|
|
46
|
-
}
|
|
47
|
-
async function compressJson(data) {
|
|
48
|
-
return _asynclzstring.compressToBase64.call(void 0, JSON.stringify(data));
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
// src/core/utils/compression/decompress.ts
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
async function decompressDataAndCheckHash(compressedData) {
|
|
55
|
-
if (!(_optionalChain([compressedData, 'optionalAccess', _2 => _2.compressed]) && _optionalChain([compressedData, 'optionalAccess', _3 => _3.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 (!_optionalChain([parsedData, 'optionalAccess', _4 => _4.validationHash])) {
|
|
71
|
-
throw new FrakRpcError(
|
|
72
|
-
RpcErrorCodes.corruptedResponse,
|
|
73
|
-
"Missing validation hash"
|
|
74
|
-
);
|
|
75
|
-
}
|
|
76
|
-
const expectedCompressedHash = _jssha256.sha256.call(void 0, 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 = _jssha256.sha256.call(void 0, 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 _asynclzstring.decompressFromBase64.call(void 0, 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
|
-
_optionalChain([iframe, 'optionalAccess', _5 => _5.addEventListener, 'call', _6 => _6("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
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
exports.FrakRpcError = FrakRpcError; exports.ClientNotFound = ClientNotFound; exports.RpcErrorCodes = RpcErrorCodes; exports.hashAndCompressData = hashAndCompressData; exports.compressJson = compressJson; exports.decompressDataAndCheckHash = decompressDataAndCheckHash; exports.decompressJson = decompressJson; exports.createIframe = createIframe; exports.changeIframeVisibility = changeIframeVisibility;
|
package/dist/chunk-HOX3RRO6.js
DELETED
|
@@ -1,199 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
FrakRpcError,
|
|
3
|
-
RpcErrorCodes,
|
|
4
|
-
changeIframeVisibility,
|
|
5
|
-
decompressDataAndCheckHash,
|
|
6
|
-
hashAndCompressData
|
|
7
|
-
} from "./chunk-TPC5PMRC.js";
|
|
8
|
-
import {
|
|
9
|
-
__publicField
|
|
10
|
-
} from "./chunk-PKBMQBKP.js";
|
|
11
|
-
|
|
12
|
-
// src/core/utils/Deferred.ts
|
|
13
|
-
var Deferred = class {
|
|
14
|
-
constructor() {
|
|
15
|
-
__publicField(this, "_promise");
|
|
16
|
-
__publicField(this, "_resolve");
|
|
17
|
-
__publicField(this, "_reject");
|
|
18
|
-
__publicField(this, "resolve", (value) => {
|
|
19
|
-
this._resolve?.(value);
|
|
20
|
-
});
|
|
21
|
-
__publicField(this, "reject", (reason) => {
|
|
22
|
-
this._reject?.(reason);
|
|
23
|
-
});
|
|
24
|
-
this._promise = new Promise((resolve, reject) => {
|
|
25
|
-
this._resolve = resolve;
|
|
26
|
-
this._reject = reject;
|
|
27
|
-
});
|
|
28
|
-
}
|
|
29
|
-
get promise() {
|
|
30
|
-
return this._promise;
|
|
31
|
-
}
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
// src/core/clients/transports/iframeChannelManager.ts
|
|
35
|
-
function createIFrameChannelManager() {
|
|
36
|
-
const channels = /* @__PURE__ */ new Map();
|
|
37
|
-
return {
|
|
38
|
-
// TODO: Better id system?? uid stuff?
|
|
39
|
-
createChannel: (resolver) => {
|
|
40
|
-
const id = Math.random().toString(36).substring(7);
|
|
41
|
-
channels.set(id, resolver);
|
|
42
|
-
return id;
|
|
43
|
-
},
|
|
44
|
-
getRpcResolver: (id) => channels.get(id),
|
|
45
|
-
removeChannel: (id) => channels.delete(id),
|
|
46
|
-
destroy: () => channels.clear()
|
|
47
|
-
};
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
// src/core/clients/transports/iframeMessageHandler.ts
|
|
51
|
-
function createIFrameMessageHandler({
|
|
52
|
-
nexusWalletUrl,
|
|
53
|
-
iframe,
|
|
54
|
-
channelManager
|
|
55
|
-
}) {
|
|
56
|
-
if (typeof window === "undefined") {
|
|
57
|
-
throw new FrakRpcError(
|
|
58
|
-
RpcErrorCodes.configError,
|
|
59
|
-
"iframe client should be used in the browser"
|
|
60
|
-
);
|
|
61
|
-
}
|
|
62
|
-
if (!iframe.contentWindow) {
|
|
63
|
-
throw new FrakRpcError(
|
|
64
|
-
RpcErrorCodes.configError,
|
|
65
|
-
"The iframe does not have a content window"
|
|
66
|
-
);
|
|
67
|
-
}
|
|
68
|
-
const contentWindow = iframe.contentWindow;
|
|
69
|
-
const isConnected = new Deferred();
|
|
70
|
-
const msgHandler = async (event) => {
|
|
71
|
-
if (!event.origin) {
|
|
72
|
-
return;
|
|
73
|
-
}
|
|
74
|
-
if (new URL(event.origin).origin.toLowerCase() !== new URL(nexusWalletUrl).origin.toLowerCase()) {
|
|
75
|
-
return;
|
|
76
|
-
}
|
|
77
|
-
if ("lifecycle" in event.data) {
|
|
78
|
-
switch (event.data.lifecycle) {
|
|
79
|
-
case "connected":
|
|
80
|
-
isConnected.resolve(true);
|
|
81
|
-
break;
|
|
82
|
-
case "show":
|
|
83
|
-
case "hide":
|
|
84
|
-
changeIframeVisibility({
|
|
85
|
-
iframe,
|
|
86
|
-
isVisible: event.data.lifecycle === "show"
|
|
87
|
-
});
|
|
88
|
-
break;
|
|
89
|
-
}
|
|
90
|
-
return;
|
|
91
|
-
}
|
|
92
|
-
const channel = event.data.id;
|
|
93
|
-
const resolver = channelManager.getRpcResolver(channel);
|
|
94
|
-
if (!resolver) {
|
|
95
|
-
return;
|
|
96
|
-
}
|
|
97
|
-
await resolver(event.data);
|
|
98
|
-
};
|
|
99
|
-
window.addEventListener("message", msgHandler);
|
|
100
|
-
const sendEvent = (message) => {
|
|
101
|
-
contentWindow.postMessage(message, {
|
|
102
|
-
targetOrigin: nexusWalletUrl
|
|
103
|
-
});
|
|
104
|
-
};
|
|
105
|
-
const cleanup = () => {
|
|
106
|
-
window.removeEventListener("message", msgHandler);
|
|
107
|
-
};
|
|
108
|
-
return {
|
|
109
|
-
isConnected: isConnected.promise,
|
|
110
|
-
sendEvent,
|
|
111
|
-
cleanup
|
|
112
|
-
};
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
// src/core/clients/createIFrameNexusClient.ts
|
|
116
|
-
function createIFrameNexusClient({
|
|
117
|
-
config,
|
|
118
|
-
iframe
|
|
119
|
-
}) {
|
|
120
|
-
const channelManager = createIFrameChannelManager();
|
|
121
|
-
const messageHandler = createIFrameMessageHandler({
|
|
122
|
-
nexusWalletUrl: config.walletUrl,
|
|
123
|
-
iframe,
|
|
124
|
-
channelManager
|
|
125
|
-
});
|
|
126
|
-
const request = async (args) => {
|
|
127
|
-
const isConnected = await messageHandler.isConnected;
|
|
128
|
-
if (!isConnected) {
|
|
129
|
-
throw new FrakRpcError(
|
|
130
|
-
RpcErrorCodes.clientNotConnected,
|
|
131
|
-
"The iframe provider isn't connected yet"
|
|
132
|
-
);
|
|
133
|
-
}
|
|
134
|
-
const result = new Deferred();
|
|
135
|
-
const channelId = channelManager.createChannel(async (message) => {
|
|
136
|
-
const decompressed = await decompressDataAndCheckHash(message.data);
|
|
137
|
-
if (decompressed.error) {
|
|
138
|
-
result.reject(
|
|
139
|
-
new FrakRpcError(
|
|
140
|
-
decompressed.error.code,
|
|
141
|
-
decompressed.error.message,
|
|
142
|
-
decompressed.error?.data
|
|
143
|
-
)
|
|
144
|
-
);
|
|
145
|
-
} else {
|
|
146
|
-
result.resolve(decompressed.result);
|
|
147
|
-
}
|
|
148
|
-
channelManager.removeChannel(channelId);
|
|
149
|
-
});
|
|
150
|
-
const compressedMessage = await hashAndCompressData(args);
|
|
151
|
-
messageHandler.sendEvent({
|
|
152
|
-
id: channelId,
|
|
153
|
-
// @ts-ignore, todo: idk why the fck it's needed
|
|
154
|
-
topic: args.method,
|
|
155
|
-
data: compressedMessage
|
|
156
|
-
});
|
|
157
|
-
return result.promise;
|
|
158
|
-
};
|
|
159
|
-
const listenerRequest = async (args, callback) => {
|
|
160
|
-
const isConnected = await messageHandler.isConnected;
|
|
161
|
-
if (!isConnected) {
|
|
162
|
-
throw new FrakRpcError(
|
|
163
|
-
RpcErrorCodes.clientNotConnected,
|
|
164
|
-
"The iframe provider isn't connected yet"
|
|
165
|
-
);
|
|
166
|
-
}
|
|
167
|
-
const channelId = channelManager.createChannel(async (message) => {
|
|
168
|
-
console.log("Will try to decompress", { message, args });
|
|
169
|
-
const decompressed = await decompressDataAndCheckHash(message.data);
|
|
170
|
-
console.log("Decompressed listening data", { args, decompressed });
|
|
171
|
-
if (decompressed.result) {
|
|
172
|
-
callback(decompressed.result);
|
|
173
|
-
} else {
|
|
174
|
-
}
|
|
175
|
-
});
|
|
176
|
-
const compressedMessage = await hashAndCompressData(args);
|
|
177
|
-
messageHandler.sendEvent({
|
|
178
|
-
id: channelId,
|
|
179
|
-
topic: args.method,
|
|
180
|
-
data: compressedMessage
|
|
181
|
-
});
|
|
182
|
-
};
|
|
183
|
-
const destroy = async () => {
|
|
184
|
-
channelManager.destroy();
|
|
185
|
-
messageHandler.cleanup();
|
|
186
|
-
iframe.remove();
|
|
187
|
-
};
|
|
188
|
-
return {
|
|
189
|
-
config,
|
|
190
|
-
waitForConnection: messageHandler.isConnected,
|
|
191
|
-
request,
|
|
192
|
-
listenerRequest,
|
|
193
|
-
destroy
|
|
194
|
-
};
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
export {
|
|
198
|
-
createIFrameNexusClient
|
|
199
|
-
};
|
package/dist/chunk-SGLR6RFA.cjs
DELETED
|
@@ -1,199 +0,0 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); 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
|
-
|
|
7
|
-
var _chunkBPFJZRJ6cjs = require('./chunk-BPFJZRJ6.cjs');
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
var _chunkETV4XYOVcjs = require('./chunk-ETV4XYOV.cjs');
|
|
11
|
-
|
|
12
|
-
// src/core/utils/Deferred.ts
|
|
13
|
-
var Deferred = class {
|
|
14
|
-
constructor() {
|
|
15
|
-
_chunkETV4XYOVcjs.__publicField.call(void 0, this, "_promise");
|
|
16
|
-
_chunkETV4XYOVcjs.__publicField.call(void 0, this, "_resolve");
|
|
17
|
-
_chunkETV4XYOVcjs.__publicField.call(void 0, this, "_reject");
|
|
18
|
-
_chunkETV4XYOVcjs.__publicField.call(void 0, this, "resolve", (value) => {
|
|
19
|
-
_optionalChain([this, 'access', _ => _._resolve, 'optionalCall', _2 => _2(value)]);
|
|
20
|
-
});
|
|
21
|
-
_chunkETV4XYOVcjs.__publicField.call(void 0, this, "reject", (reason) => {
|
|
22
|
-
_optionalChain([this, 'access', _3 => _3._reject, 'optionalCall', _4 => _4(reason)]);
|
|
23
|
-
});
|
|
24
|
-
this._promise = new Promise((resolve, reject) => {
|
|
25
|
-
this._resolve = resolve;
|
|
26
|
-
this._reject = reject;
|
|
27
|
-
});
|
|
28
|
-
}
|
|
29
|
-
get promise() {
|
|
30
|
-
return this._promise;
|
|
31
|
-
}
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
// src/core/clients/transports/iframeChannelManager.ts
|
|
35
|
-
function createIFrameChannelManager() {
|
|
36
|
-
const channels = /* @__PURE__ */ new Map();
|
|
37
|
-
return {
|
|
38
|
-
// TODO: Better id system?? uid stuff?
|
|
39
|
-
createChannel: (resolver) => {
|
|
40
|
-
const id = Math.random().toString(36).substring(7);
|
|
41
|
-
channels.set(id, resolver);
|
|
42
|
-
return id;
|
|
43
|
-
},
|
|
44
|
-
getRpcResolver: (id) => channels.get(id),
|
|
45
|
-
removeChannel: (id) => channels.delete(id),
|
|
46
|
-
destroy: () => channels.clear()
|
|
47
|
-
};
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
// src/core/clients/transports/iframeMessageHandler.ts
|
|
51
|
-
function createIFrameMessageHandler({
|
|
52
|
-
nexusWalletUrl,
|
|
53
|
-
iframe,
|
|
54
|
-
channelManager
|
|
55
|
-
}) {
|
|
56
|
-
if (typeof window === "undefined") {
|
|
57
|
-
throw new (0, _chunkBPFJZRJ6cjs.FrakRpcError)(
|
|
58
|
-
_chunkBPFJZRJ6cjs.RpcErrorCodes.configError,
|
|
59
|
-
"iframe client should be used in the browser"
|
|
60
|
-
);
|
|
61
|
-
}
|
|
62
|
-
if (!iframe.contentWindow) {
|
|
63
|
-
throw new (0, _chunkBPFJZRJ6cjs.FrakRpcError)(
|
|
64
|
-
_chunkBPFJZRJ6cjs.RpcErrorCodes.configError,
|
|
65
|
-
"The iframe does not have a content window"
|
|
66
|
-
);
|
|
67
|
-
}
|
|
68
|
-
const contentWindow = iframe.contentWindow;
|
|
69
|
-
const isConnected = new Deferred();
|
|
70
|
-
const msgHandler = async (event) => {
|
|
71
|
-
if (!event.origin) {
|
|
72
|
-
return;
|
|
73
|
-
}
|
|
74
|
-
if (new URL(event.origin).origin.toLowerCase() !== new URL(nexusWalletUrl).origin.toLowerCase()) {
|
|
75
|
-
return;
|
|
76
|
-
}
|
|
77
|
-
if ("lifecycle" in event.data) {
|
|
78
|
-
switch (event.data.lifecycle) {
|
|
79
|
-
case "connected":
|
|
80
|
-
isConnected.resolve(true);
|
|
81
|
-
break;
|
|
82
|
-
case "show":
|
|
83
|
-
case "hide":
|
|
84
|
-
_chunkBPFJZRJ6cjs.changeIframeVisibility.call(void 0, {
|
|
85
|
-
iframe,
|
|
86
|
-
isVisible: event.data.lifecycle === "show"
|
|
87
|
-
});
|
|
88
|
-
break;
|
|
89
|
-
}
|
|
90
|
-
return;
|
|
91
|
-
}
|
|
92
|
-
const channel = event.data.id;
|
|
93
|
-
const resolver = channelManager.getRpcResolver(channel);
|
|
94
|
-
if (!resolver) {
|
|
95
|
-
return;
|
|
96
|
-
}
|
|
97
|
-
await resolver(event.data);
|
|
98
|
-
};
|
|
99
|
-
window.addEventListener("message", msgHandler);
|
|
100
|
-
const sendEvent = (message) => {
|
|
101
|
-
contentWindow.postMessage(message, {
|
|
102
|
-
targetOrigin: nexusWalletUrl
|
|
103
|
-
});
|
|
104
|
-
};
|
|
105
|
-
const cleanup = () => {
|
|
106
|
-
window.removeEventListener("message", msgHandler);
|
|
107
|
-
};
|
|
108
|
-
return {
|
|
109
|
-
isConnected: isConnected.promise,
|
|
110
|
-
sendEvent,
|
|
111
|
-
cleanup
|
|
112
|
-
};
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
// src/core/clients/createIFrameNexusClient.ts
|
|
116
|
-
function createIFrameNexusClient({
|
|
117
|
-
config,
|
|
118
|
-
iframe
|
|
119
|
-
}) {
|
|
120
|
-
const channelManager = createIFrameChannelManager();
|
|
121
|
-
const messageHandler = createIFrameMessageHandler({
|
|
122
|
-
nexusWalletUrl: config.walletUrl,
|
|
123
|
-
iframe,
|
|
124
|
-
channelManager
|
|
125
|
-
});
|
|
126
|
-
const request = async (args) => {
|
|
127
|
-
const isConnected = await messageHandler.isConnected;
|
|
128
|
-
if (!isConnected) {
|
|
129
|
-
throw new (0, _chunkBPFJZRJ6cjs.FrakRpcError)(
|
|
130
|
-
_chunkBPFJZRJ6cjs.RpcErrorCodes.clientNotConnected,
|
|
131
|
-
"The iframe provider isn't connected yet"
|
|
132
|
-
);
|
|
133
|
-
}
|
|
134
|
-
const result = new Deferred();
|
|
135
|
-
const channelId = channelManager.createChannel(async (message) => {
|
|
136
|
-
const decompressed = await _chunkBPFJZRJ6cjs.decompressDataAndCheckHash.call(void 0, message.data);
|
|
137
|
-
if (decompressed.error) {
|
|
138
|
-
result.reject(
|
|
139
|
-
new (0, _chunkBPFJZRJ6cjs.FrakRpcError)(
|
|
140
|
-
decompressed.error.code,
|
|
141
|
-
decompressed.error.message,
|
|
142
|
-
_optionalChain([decompressed, 'access', _5 => _5.error, 'optionalAccess', _6 => _6.data])
|
|
143
|
-
)
|
|
144
|
-
);
|
|
145
|
-
} else {
|
|
146
|
-
result.resolve(decompressed.result);
|
|
147
|
-
}
|
|
148
|
-
channelManager.removeChannel(channelId);
|
|
149
|
-
});
|
|
150
|
-
const compressedMessage = await _chunkBPFJZRJ6cjs.hashAndCompressData.call(void 0, args);
|
|
151
|
-
messageHandler.sendEvent({
|
|
152
|
-
id: channelId,
|
|
153
|
-
// @ts-ignore, todo: idk why the fck it's needed
|
|
154
|
-
topic: args.method,
|
|
155
|
-
data: compressedMessage
|
|
156
|
-
});
|
|
157
|
-
return result.promise;
|
|
158
|
-
};
|
|
159
|
-
const listenerRequest = async (args, callback) => {
|
|
160
|
-
const isConnected = await messageHandler.isConnected;
|
|
161
|
-
if (!isConnected) {
|
|
162
|
-
throw new (0, _chunkBPFJZRJ6cjs.FrakRpcError)(
|
|
163
|
-
_chunkBPFJZRJ6cjs.RpcErrorCodes.clientNotConnected,
|
|
164
|
-
"The iframe provider isn't connected yet"
|
|
165
|
-
);
|
|
166
|
-
}
|
|
167
|
-
const channelId = channelManager.createChannel(async (message) => {
|
|
168
|
-
console.log("Will try to decompress", { message, args });
|
|
169
|
-
const decompressed = await _chunkBPFJZRJ6cjs.decompressDataAndCheckHash.call(void 0, message.data);
|
|
170
|
-
console.log("Decompressed listening data", { args, decompressed });
|
|
171
|
-
if (decompressed.result) {
|
|
172
|
-
callback(decompressed.result);
|
|
173
|
-
} else {
|
|
174
|
-
}
|
|
175
|
-
});
|
|
176
|
-
const compressedMessage = await _chunkBPFJZRJ6cjs.hashAndCompressData.call(void 0, args);
|
|
177
|
-
messageHandler.sendEvent({
|
|
178
|
-
id: channelId,
|
|
179
|
-
topic: args.method,
|
|
180
|
-
data: compressedMessage
|
|
181
|
-
});
|
|
182
|
-
};
|
|
183
|
-
const destroy = async () => {
|
|
184
|
-
channelManager.destroy();
|
|
185
|
-
messageHandler.cleanup();
|
|
186
|
-
iframe.remove();
|
|
187
|
-
};
|
|
188
|
-
return {
|
|
189
|
-
config,
|
|
190
|
-
waitForConnection: messageHandler.isConnected,
|
|
191
|
-
request,
|
|
192
|
-
listenerRequest,
|
|
193
|
-
destroy
|
|
194
|
-
};
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
exports.createIFrameNexusClient = createIFrameNexusClient;
|