@bitsocial/bitsocial-react-hooks 0.1.0
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/LICENSE +674 -0
- package/README.md +1365 -0
- package/dist/hooks/accounts/accounts.d.ts +64 -0
- package/dist/hooks/accounts/accounts.d.ts.map +1 -0
- package/dist/hooks/accounts/accounts.js +706 -0
- package/dist/hooks/accounts/accounts.js.map +1 -0
- package/dist/hooks/accounts/index.d.ts +2 -0
- package/dist/hooks/accounts/index.d.ts.map +1 -0
- package/dist/hooks/accounts/index.js +2 -0
- package/dist/hooks/accounts/index.js.map +1 -0
- package/dist/hooks/accounts/utils.d.ts +6 -0
- package/dist/hooks/accounts/utils.d.ts.map +1 -0
- package/dist/hooks/accounts/utils.js +226 -0
- package/dist/hooks/accounts/utils.js.map +1 -0
- package/dist/hooks/actions/actions.d.ts +19 -0
- package/dist/hooks/actions/actions.d.ts.map +1 -0
- package/dist/hooks/actions/actions.js +552 -0
- package/dist/hooks/actions/actions.js.map +1 -0
- package/dist/hooks/actions/index.d.ts +2 -0
- package/dist/hooks/actions/index.d.ts.map +1 -0
- package/dist/hooks/actions/index.js +2 -0
- package/dist/hooks/actions/index.js.map +1 -0
- package/dist/hooks/authors/author-avatars.d.ts +28 -0
- package/dist/hooks/authors/author-avatars.d.ts.map +1 -0
- package/dist/hooks/authors/author-avatars.js +191 -0
- package/dist/hooks/authors/author-avatars.js.map +1 -0
- package/dist/hooks/authors/authors.d.ts +37 -0
- package/dist/hooks/authors/authors.d.ts.map +1 -0
- package/dist/hooks/authors/authors.js +509 -0
- package/dist/hooks/authors/authors.js.map +1 -0
- package/dist/hooks/authors/index.d.ts +2 -0
- package/dist/hooks/authors/index.d.ts.map +1 -0
- package/dist/hooks/authors/index.js +2 -0
- package/dist/hooks/authors/index.js.map +1 -0
- package/dist/hooks/authors/utils.d.ts +4 -0
- package/dist/hooks/authors/utils.d.ts.map +1 -0
- package/dist/hooks/authors/utils.js +21 -0
- package/dist/hooks/authors/utils.js.map +1 -0
- package/dist/hooks/comments.d.ts +17 -0
- package/dist/hooks/comments.d.ts.map +1 -0
- package/dist/hooks/comments.js +351 -0
- package/dist/hooks/comments.js.map +1 -0
- package/dist/hooks/communities.d.ts +31 -0
- package/dist/hooks/communities.d.ts.map +1 -0
- package/dist/hooks/communities.js +389 -0
- package/dist/hooks/communities.js.map +1 -0
- package/dist/hooks/feeds/feeds.d.ts +18 -0
- package/dist/hooks/feeds/feeds.d.ts.map +1 -0
- package/dist/hooks/feeds/feeds.js +315 -0
- package/dist/hooks/feeds/feeds.js.map +1 -0
- package/dist/hooks/feeds/index.d.ts +2 -0
- package/dist/hooks/feeds/index.d.ts.map +1 -0
- package/dist/hooks/feeds/index.js +2 -0
- package/dist/hooks/feeds/index.js.map +1 -0
- package/dist/hooks/pkc-rpc.d.ts +7 -0
- package/dist/hooks/pkc-rpc.d.ts.map +1 -0
- package/dist/hooks/pkc-rpc.js +88 -0
- package/dist/hooks/pkc-rpc.js.map +1 -0
- package/dist/hooks/replies.d.ts +5 -0
- package/dist/hooks/replies.d.ts.map +1 -0
- package/dist/hooks/replies.js +155 -0
- package/dist/hooks/replies.js.map +1 -0
- package/dist/hooks/states.d.ts +15 -0
- package/dist/hooks/states.d.ts.map +1 -0
- package/dist/hooks/states.js +213 -0
- package/dist/hooks/states.js.map +1 -0
- package/dist/hooks/utils/use-interval.d.ts +3 -0
- package/dist/hooks/utils/use-interval.d.ts.map +1 -0
- package/dist/hooks/utils/use-interval.js +36 -0
- package/dist/hooks/utils/use-interval.js.map +1 -0
- package/dist/hooks/utils/use-previous.d.ts +1 -0
- package/dist/hooks/utils/use-previous.js +10 -0
- package/dist/index.d.ts +82 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +128 -0
- package/dist/index.js.map +1 -0
- package/dist/lib/chain/chain.d.ts +36 -0
- package/dist/lib/chain/chain.d.ts.map +1 -0
- package/dist/lib/chain/chain.js +195 -0
- package/dist/lib/chain/chain.js.map +1 -0
- package/dist/lib/chain/index.d.ts +4 -0
- package/dist/lib/chain/index.d.ts.map +1 -0
- package/dist/lib/chain/index.js +4 -0
- package/dist/lib/chain/index.js.map +1 -0
- package/dist/lib/community-address.d.ts +6 -0
- package/dist/lib/community-address.d.ts.map +1 -0
- package/dist/lib/community-address.js +26 -0
- package/dist/lib/community-address.js.map +1 -0
- package/dist/lib/community-ref.d.ts +23 -0
- package/dist/lib/community-ref.d.ts.map +1 -0
- package/dist/lib/community-ref.js +113 -0
- package/dist/lib/community-ref.js.map +1 -0
- package/dist/lib/debug-utils.d.ts +9 -0
- package/dist/lib/debug-utils.d.ts.map +1 -0
- package/dist/lib/debug-utils.js +21 -0
- package/dist/lib/debug-utils.js.map +1 -0
- package/dist/lib/feed-sort-type.d.ts +2 -0
- package/dist/lib/feed-sort-type.d.ts.map +1 -0
- package/dist/lib/feed-sort-type.js +22 -0
- package/dist/lib/feed-sort-type.js.map +1 -0
- package/dist/lib/localforage-lru/index.d.ts +3 -0
- package/dist/lib/localforage-lru/index.d.ts.map +1 -0
- package/dist/lib/localforage-lru/index.js +46 -0
- package/dist/lib/localforage-lru/index.js.map +1 -0
- package/dist/lib/localforage-lru/localforage-lru.d.ts +6 -0
- package/dist/lib/localforage-lru/localforage-lru.d.ts.map +1 -0
- package/dist/lib/localforage-lru/localforage-lru.js +182 -0
- package/dist/lib/localforage-lru/localforage-lru.js.map +1 -0
- package/dist/lib/pkc-compat.d.ts +25 -0
- package/dist/lib/pkc-compat.d.ts.map +1 -0
- package/dist/lib/pkc-compat.js +131 -0
- package/dist/lib/pkc-compat.js.map +1 -0
- package/dist/lib/pkc-js/fixtures/markdown-example.d.ts +3 -0
- package/dist/lib/pkc-js/fixtures/markdown-example.d.ts.map +1 -0
- package/dist/lib/pkc-js/fixtures/markdown-example.js +280 -0
- package/dist/lib/pkc-js/fixtures/markdown-example.js.map +1 -0
- package/dist/lib/pkc-js/index.d.ts +11 -0
- package/dist/lib/pkc-js/index.d.ts.map +1 -0
- package/dist/lib/pkc-js/index.js +85 -0
- package/dist/lib/pkc-js/index.js.map +1 -0
- package/dist/lib/pkc-js/pkc-js-mock-content.d.ts +3 -0
- package/dist/lib/pkc-js/pkc-js-mock-content.d.ts.map +1 -0
- package/dist/lib/pkc-js/pkc-js-mock-content.js +1235 -0
- package/dist/lib/pkc-js/pkc-js-mock-content.js.map +1 -0
- package/dist/lib/pkc-js/pkc-js-mock.d.ts +137 -0
- package/dist/lib/pkc-js/pkc-js-mock.d.ts.map +1 -0
- package/dist/lib/pkc-js/pkc-js-mock.js +644 -0
- package/dist/lib/pkc-js/pkc-js-mock.js.map +1 -0
- package/dist/lib/polyfill.d.ts +3 -0
- package/dist/lib/polyfill.d.ts.map +1 -0
- package/dist/lib/polyfill.js +14 -0
- package/dist/lib/polyfill.js.map +1 -0
- package/dist/lib/protocol-compat.d.ts +14 -0
- package/dist/lib/protocol-compat.d.ts.map +1 -0
- package/dist/lib/protocol-compat.js +67 -0
- package/dist/lib/protocol-compat.js.map +1 -0
- package/dist/lib/test-utils.d.ts +29 -0
- package/dist/lib/test-utils.d.ts.map +1 -0
- package/dist/lib/test-utils.js +184 -0
- package/dist/lib/test-utils.js.map +1 -0
- package/dist/lib/utils/comment-moderation.d.ts +4 -0
- package/dist/lib/utils/comment-moderation.d.ts.map +1 -0
- package/dist/lib/utils/comment-moderation.js +56 -0
- package/dist/lib/utils/comment-moderation.js.map +1 -0
- package/dist/lib/utils/index.d.ts +4 -0
- package/dist/lib/utils/index.d.ts.map +1 -0
- package/dist/lib/utils/index.js +4 -0
- package/dist/lib/utils/index.js.map +1 -0
- package/dist/lib/utils/utils.d.ts +23 -0
- package/dist/lib/utils/utils.d.ts.map +1 -0
- package/dist/lib/utils/utils.js +375 -0
- package/dist/lib/utils/utils.js.map +1 -0
- package/dist/lib/validator.d.ts +30 -0
- package/dist/lib/validator.d.ts.map +1 -0
- package/dist/lib/validator.js +307 -0
- package/dist/lib/validator.js.map +1 -0
- package/dist/stores/accounts/account-generator.d.ts +51 -0
- package/dist/stores/accounts/account-generator.d.ts.map +1 -0
- package/dist/stores/accounts/account-generator.js +160 -0
- package/dist/stores/accounts/account-generator.js.map +1 -0
- package/dist/stores/accounts/accounts-actions-internal.d.ts +8 -0
- package/dist/stores/accounts/accounts-actions-internal.d.ts.map +1 -0
- package/dist/stores/accounts/accounts-actions-internal.js +403 -0
- package/dist/stores/accounts/accounts-actions-internal.js.map +1 -0
- package/dist/stores/accounts/accounts-actions.d.ts +46 -0
- package/dist/stores/accounts/accounts-actions.d.ts.map +1 -0
- package/dist/stores/accounts/accounts-actions.js +1341 -0
- package/dist/stores/accounts/accounts-actions.js.map +1 -0
- package/dist/stores/accounts/accounts-database.d.ts +34 -0
- package/dist/stores/accounts/accounts-database.d.ts.map +1 -0
- package/dist/stores/accounts/accounts-database.js +685 -0
- package/dist/stores/accounts/accounts-database.js.map +1 -0
- package/dist/stores/accounts/accounts-store.d.ts +32 -0
- package/dist/stores/accounts/accounts-store.d.ts.map +1 -0
- package/dist/stores/accounts/accounts-store.js +169 -0
- package/dist/stores/accounts/accounts-store.js.map +1 -0
- package/dist/stores/accounts/index.d.ts +4 -0
- package/dist/stores/accounts/index.d.ts.map +1 -0
- package/dist/stores/accounts/index.js +4 -0
- package/dist/stores/accounts/index.js.map +1 -0
- package/dist/stores/accounts/utils.d.ts +49 -0
- package/dist/stores/accounts/utils.d.ts.map +1 -0
- package/dist/stores/accounts/utils.js +419 -0
- package/dist/stores/accounts/utils.js.map +1 -0
- package/dist/stores/authors-comments/authors-comments-store.d.ts +37 -0
- package/dist/stores/authors-comments/authors-comments-store.d.ts.map +1 -0
- package/dist/stores/authors-comments/authors-comments-store.js +338 -0
- package/dist/stores/authors-comments/authors-comments-store.js.map +1 -0
- package/dist/stores/authors-comments/index.d.ts +4 -0
- package/dist/stores/authors-comments/index.d.ts.map +1 -0
- package/dist/stores/authors-comments/index.js +4 -0
- package/dist/stores/authors-comments/index.js.map +1 -0
- package/dist/stores/authors-comments/utils.d.ts +14 -0
- package/dist/stores/authors-comments/utils.d.ts.map +1 -0
- package/dist/stores/authors-comments/utils.js +81 -0
- package/dist/stores/authors-comments/utils.js.map +1 -0
- package/dist/stores/comments/comments-store.d.ts +19 -0
- package/dist/stores/comments/comments-store.d.ts.map +1 -0
- package/dist/stores/comments/comments-store.js +385 -0
- package/dist/stores/comments/comments-store.js.map +1 -0
- package/dist/stores/comments/index.d.ts +4 -0
- package/dist/stores/comments/index.d.ts.map +1 -0
- package/dist/stores/comments/index.js +4 -0
- package/dist/stores/comments/index.js.map +1 -0
- package/dist/stores/communities/communities-store.d.ts +17 -0
- package/dist/stores/communities/communities-store.d.ts.map +1 -0
- package/dist/stores/communities/communities-store.js +304 -0
- package/dist/stores/communities/communities-store.js.map +1 -0
- package/dist/stores/communities/index.d.ts +4 -0
- package/dist/stores/communities/index.d.ts.map +1 -0
- package/dist/stores/communities/index.js +4 -0
- package/dist/stores/communities/index.js.map +1 -0
- package/dist/stores/communities-pages/communities-pages-store.d.ts +23 -0
- package/dist/stores/communities-pages/communities-pages-store.d.ts.map +1 -0
- package/dist/stores/communities-pages/communities-pages-store.js +316 -0
- package/dist/stores/communities-pages/communities-pages-store.js.map +1 -0
- package/dist/stores/communities-pages/index.d.ts +4 -0
- package/dist/stores/communities-pages/index.d.ts.map +1 -0
- package/dist/stores/communities-pages/index.js +4 -0
- package/dist/stores/communities-pages/index.js.map +1 -0
- package/dist/stores/feeds/feed-sorter.d.ts +5 -0
- package/dist/stores/feeds/feed-sorter.d.ts.map +1 -0
- package/dist/stores/feeds/feed-sorter.js +135 -0
- package/dist/stores/feeds/feed-sorter.js.map +1 -0
- package/dist/stores/feeds/feeds-store.d.ts +25 -0
- package/dist/stores/feeds/feeds-store.d.ts.map +1 -0
- package/dist/stores/feeds/feeds-store.js +459 -0
- package/dist/stores/feeds/feeds-store.js.map +1 -0
- package/dist/stores/feeds/index.d.ts +4 -0
- package/dist/stores/feeds/index.d.ts.map +1 -0
- package/dist/stores/feeds/index.js +4 -0
- package/dist/stores/feeds/index.js.map +1 -0
- package/dist/stores/feeds/utils.d.ts +43 -0
- package/dist/stores/feeds/utils.d.ts.map +1 -0
- package/dist/stores/feeds/utils.js +736 -0
- package/dist/stores/feeds/utils.js.map +1 -0
- package/dist/stores/replies/index.d.ts +4 -0
- package/dist/stores/replies/index.d.ts.map +1 -0
- package/dist/stores/replies/index.js +4 -0
- package/dist/stores/replies/index.js.map +1 -0
- package/dist/stores/replies/replies-comments-store.d.ts +8 -0
- package/dist/stores/replies/replies-comments-store.d.ts.map +1 -0
- package/dist/stores/replies/replies-comments-store.js +23 -0
- package/dist/stores/replies/replies-comments-store.js.map +1 -0
- package/dist/stores/replies/replies-store.d.ts +29 -0
- package/dist/stores/replies/replies-store.d.ts.map +1 -0
- package/dist/stores/replies/replies-store.js +413 -0
- package/dist/stores/replies/replies-store.js.map +1 -0
- package/dist/stores/replies/utils.d.ts +25 -0
- package/dist/stores/replies/utils.d.ts.map +1 -0
- package/dist/stores/replies/utils.js +549 -0
- package/dist/stores/replies/utils.js.map +1 -0
- package/dist/stores/replies-pages/index.d.ts +4 -0
- package/dist/stores/replies-pages/index.d.ts.map +1 -0
- package/dist/stores/replies-pages/index.js +4 -0
- package/dist/stores/replies-pages/index.js.map +1 -0
- package/dist/stores/replies-pages/replies-pages-store.d.ts +20 -0
- package/dist/stores/replies-pages/replies-pages-store.d.ts.map +1 -0
- package/dist/stores/replies-pages/replies-pages-store.js +270 -0
- package/dist/stores/replies-pages/replies-pages-store.js.map +1 -0
- package/dist/stores/replies-pages/utils.d.ts +3 -0
- package/dist/stores/replies-pages/utils.d.ts.map +1 -0
- package/dist/stores/replies-pages/utils.js +43 -0
- package/dist/stores/replies-pages/utils.js.map +1 -0
- package/dist/types.d.ts +638 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +3 -0
- package/dist/types.js.map +1 -0
- package/package.json +160 -0
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import assert from "assert";
|
|
2
|
+
import { BsoResolver } from "@bitsocial/bso-resolver";
|
|
3
|
+
export const getProtocolClient = (account) => account === null || account === void 0 ? void 0 : account.pkc;
|
|
4
|
+
export const getProtocolOptions = (account) => account === null || account === void 0 ? void 0 : account.pkcOptions;
|
|
5
|
+
export const getChainProviders = (account) => { var _a; return (account === null || account === void 0 ? void 0 : account.chainProviders) || ((_a = getProtocolOptions(account)) === null || _a === void 0 ? void 0 : _a.chainProviders); };
|
|
6
|
+
export const getNameResolversChainProviders = (account) => { var _a; return (account === null || account === void 0 ? void 0 : account.nameResolversChainProviders) || ((_a = getProtocolOptions(account)) === null || _a === void 0 ? void 0 : _a.nameResolversChainProviders); };
|
|
7
|
+
export const getRpcClients = (protocolClient) => { var _a; return ((_a = protocolClient === null || protocolClient === void 0 ? void 0 : protocolClient.clients) === null || _a === void 0 ? void 0 : _a.pkcRpcClients) || {}; };
|
|
8
|
+
export const getPageRpcClients = (clients) => (clients === null || clients === void 0 ? void 0 : clients.pkcRpcClients) || {};
|
|
9
|
+
export const getProtocolNameResolverClients = (protocolClient) => {
|
|
10
|
+
var _a, _b, _c;
|
|
11
|
+
return ((_a = protocolClient === null || protocolClient === void 0 ? void 0 : protocolClient.clients) === null || _a === void 0 ? void 0 : _a.nameResolvers) ||
|
|
12
|
+
((_c = (_b = protocolClient === null || protocolClient === void 0 ? void 0 : protocolClient._clientsManager) === null || _b === void 0 ? void 0 : _b.clients) === null || _c === void 0 ? void 0 : _c.nameResolvers) ||
|
|
13
|
+
{};
|
|
14
|
+
};
|
|
15
|
+
const isEthAliasDomain = (address) => typeof address === "string" &&
|
|
16
|
+
(address.toLowerCase().endsWith(".eth") || address.toLowerCase().endsWith(".bso"));
|
|
17
|
+
const isSupportedBsoResolverProvider = (provider) => provider === "viem" || /^(https?:\/\/|wss?:\/\/)/i.test(provider);
|
|
18
|
+
const getNameResolverProviderLabel = (provider) => {
|
|
19
|
+
try {
|
|
20
|
+
return new URL(provider).hostname;
|
|
21
|
+
}
|
|
22
|
+
catch (error) {
|
|
23
|
+
return provider;
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
const getConfiguredEthNameResolverProviders = (account) => {
|
|
27
|
+
var _a, _b, _c, _d;
|
|
28
|
+
const nameResolverUrls = (_b = (_a = getNameResolversChainProviders(account)) === null || _a === void 0 ? void 0 : _a.eth) === null || _b === void 0 ? void 0 : _b.urls;
|
|
29
|
+
const chainProviderUrls = (_d = (_c = getChainProviders(account)) === null || _c === void 0 ? void 0 : _c.eth) === null || _d === void 0 ? void 0 : _d.urls;
|
|
30
|
+
const urls = Array.isArray(nameResolverUrls) && nameResolverUrls.length
|
|
31
|
+
? nameResolverUrls
|
|
32
|
+
: chainProviderUrls;
|
|
33
|
+
if (!Array.isArray(urls)) {
|
|
34
|
+
return [];
|
|
35
|
+
}
|
|
36
|
+
return urls.filter((provider) => typeof provider === "string" && provider.length > 0);
|
|
37
|
+
};
|
|
38
|
+
export const getConfiguredNameResolverInfoByKey = (account) => {
|
|
39
|
+
const infoByKey = {};
|
|
40
|
+
for (const provider of getConfiguredEthNameResolverProviders(account)) {
|
|
41
|
+
if (!isSupportedBsoResolverProvider(provider)) {
|
|
42
|
+
continue;
|
|
43
|
+
}
|
|
44
|
+
const providerLabel = getNameResolverProviderLabel(provider);
|
|
45
|
+
const key = `eth-${providerLabel}`;
|
|
46
|
+
if (!infoByKey[key]) {
|
|
47
|
+
infoByKey[key] = {
|
|
48
|
+
key,
|
|
49
|
+
nameSystem: "eth",
|
|
50
|
+
chainTicker: "eth",
|
|
51
|
+
provider,
|
|
52
|
+
providerLabel,
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
return infoByKey;
|
|
57
|
+
};
|
|
58
|
+
export const getMatchingNameResolvers = (account, address) => {
|
|
59
|
+
if (!isEthAliasDomain(address)) {
|
|
60
|
+
return [];
|
|
61
|
+
}
|
|
62
|
+
return Object.values(getConfiguredNameResolverInfoByKey(account));
|
|
63
|
+
};
|
|
64
|
+
const buildConfiguredNameResolvers = (account, dataPath) => Object.values(getConfiguredNameResolverInfoByKey(account)).map((resolverInfo) => new BsoResolver({
|
|
65
|
+
key: resolverInfo.key,
|
|
66
|
+
provider: resolverInfo.provider,
|
|
67
|
+
dataPath,
|
|
68
|
+
}));
|
|
69
|
+
export const resolveAuthorNameWithProtocol = (protocolClient, options) => {
|
|
70
|
+
const resolveAuthorName = (protocolClient === null || protocolClient === void 0 ? void 0 : protocolClient.resolveAuthorAddress) || (protocolClient === null || protocolClient === void 0 ? void 0 : protocolClient.resolveAuthorName);
|
|
71
|
+
assert(typeof resolveAuthorName === "function", "protocol client resolveAuthorName/resolveAuthorAddress missing");
|
|
72
|
+
return resolveAuthorName.call(protocolClient, options);
|
|
73
|
+
};
|
|
74
|
+
export const normalizeOptionsForPkcClient = (options) => {
|
|
75
|
+
if (!options) {
|
|
76
|
+
return options;
|
|
77
|
+
}
|
|
78
|
+
const normalized = Object.assign({}, options);
|
|
79
|
+
if (normalized.resolveAuthorNames == null && normalized.resolveAuthorAddresses != null) {
|
|
80
|
+
normalized.resolveAuthorNames = normalized.resolveAuthorAddresses;
|
|
81
|
+
}
|
|
82
|
+
delete normalized.resolveAuthorAddresses;
|
|
83
|
+
delete normalized.chainProviders;
|
|
84
|
+
delete normalized.nameResolversChainProviders;
|
|
85
|
+
return normalized;
|
|
86
|
+
};
|
|
87
|
+
export const getPkcClientOptions = (account, options) => {
|
|
88
|
+
const normalized = normalizeOptionsForPkcClient(options);
|
|
89
|
+
if (!normalized) {
|
|
90
|
+
return normalized;
|
|
91
|
+
}
|
|
92
|
+
const nameResolvers = buildConfiguredNameResolvers(account, normalized.dataPath);
|
|
93
|
+
if (nameResolvers.length) {
|
|
94
|
+
normalized.nameResolvers = nameResolvers;
|
|
95
|
+
}
|
|
96
|
+
return normalized;
|
|
97
|
+
};
|
|
98
|
+
export const normalizeAccountProtocolConfig = (account, defaultChainProviders) => {
|
|
99
|
+
if (!account) {
|
|
100
|
+
return account;
|
|
101
|
+
}
|
|
102
|
+
const nextAccount = Object.assign({}, account);
|
|
103
|
+
const protocolOptions = nextAccount.pkcOptions && typeof nextAccount.pkcOptions === "object"
|
|
104
|
+
? Object.assign({}, nextAccount.pkcOptions) : nextAccount.pkcOptions;
|
|
105
|
+
const chainProviders = nextAccount.chainProviders || (protocolOptions === null || protocolOptions === void 0 ? void 0 : protocolOptions.chainProviders) || defaultChainProviders;
|
|
106
|
+
if (chainProviders !== undefined) {
|
|
107
|
+
nextAccount.chainProviders = chainProviders;
|
|
108
|
+
}
|
|
109
|
+
if (nextAccount.nameResolversChainProviders === undefined &&
|
|
110
|
+
(protocolOptions === null || protocolOptions === void 0 ? void 0 : protocolOptions.nameResolversChainProviders) !== undefined) {
|
|
111
|
+
nextAccount.nameResolversChainProviders = protocolOptions.nameResolversChainProviders;
|
|
112
|
+
}
|
|
113
|
+
if (protocolOptions && typeof protocolOptions === "object") {
|
|
114
|
+
delete protocolOptions.chainProviders;
|
|
115
|
+
delete protocolOptions.nameResolversChainProviders;
|
|
116
|
+
nextAccount.pkcOptions = protocolOptions;
|
|
117
|
+
}
|
|
118
|
+
return nextAccount;
|
|
119
|
+
};
|
|
120
|
+
export const withProtocolAliases = (account, protocolClient, protocolOptions) => {
|
|
121
|
+
const nextAccount = Object.assign({}, account);
|
|
122
|
+
if (protocolClient !== undefined) {
|
|
123
|
+
nextAccount.pkc = protocolClient;
|
|
124
|
+
}
|
|
125
|
+
if (protocolOptions !== undefined) {
|
|
126
|
+
nextAccount.pkcOptions = protocolOptions;
|
|
127
|
+
}
|
|
128
|
+
return nextAccount;
|
|
129
|
+
};
|
|
130
|
+
export * from "./protocol-compat.js";
|
|
131
|
+
//# sourceMappingURL=pkc-compat.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pkc-compat.js","sourceRoot":"","sources":["../../src/lib/pkc-compat.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,QAAQ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SAAS,EAAE,CAAC;QACjC,WAAW,CAAC,GAAG,GAAG,cAAc,CAAC;IACnC,CAAC;IACD,IAAI,eAAe,KAAK,SAAS,EAAE,CAAC;QAClC,WAAW,CAAC,UAAU,GAAG,eAAe,CAAC;IAC3C,CAAC;IAED,OAAO,WAAgB,CAAC;AAC1B,CAAC,CAAC;AAEF,cAAc,mBAAmB,CAAC","sourcesContent":["import assert from \"assert\";\nimport { BsoResolver } from \"@bitsocial/bso-resolver\";\n\nexport const getProtocolClient = (account: any) => account?.pkc;\n\nexport const getProtocolOptions = (account: any) => account?.pkcOptions;\n\nexport const getChainProviders = (account: any) =>\n account?.chainProviders || getProtocolOptions(account)?.chainProviders;\n\nexport const getNameResolversChainProviders = (account: any) =>\n account?.nameResolversChainProviders || getProtocolOptions(account)?.nameResolversChainProviders;\n\nexport const getRpcClients = (protocolClient: any) => protocolClient?.clients?.pkcRpcClients || {};\n\nexport const getPageRpcClients = (clients: any) => clients?.pkcRpcClients || {};\n\nexport const getProtocolNameResolverClients = (protocolClient: any) =>\n protocolClient?.clients?.nameResolvers ||\n protocolClient?._clientsManager?.clients?.nameResolvers ||\n {};\n\nexport type NameResolverInfo = {\n key: string;\n nameSystem: string;\n chainTicker: string;\n provider: string;\n providerLabel: string;\n};\n\nconst isEthAliasDomain = (address?: string) =>\n typeof address === \"string\" &&\n (address.toLowerCase().endsWith(\".eth\") || address.toLowerCase().endsWith(\".bso\"));\n\nconst isSupportedBsoResolverProvider = (provider: string) =>\n provider === \"viem\" || /^(https?:\\/\\/|wss?:\\/\\/)/i.test(provider);\n\nconst getNameResolverProviderLabel = (provider: string) => {\n try {\n return new URL(provider).hostname;\n } catch (error) {\n return provider;\n }\n};\n\nconst getConfiguredEthNameResolverProviders = (account: any): string[] => {\n const nameResolverUrls = getNameResolversChainProviders(account)?.eth?.urls;\n const chainProviderUrls = getChainProviders(account)?.eth?.urls;\n const urls =\n Array.isArray(nameResolverUrls) && nameResolverUrls.length\n ? nameResolverUrls\n : chainProviderUrls;\n\n if (!Array.isArray(urls)) {\n return [];\n }\n\n return urls.filter(\n (provider): provider is string => typeof provider === \"string\" && provider.length > 0,\n );\n};\n\nexport const getConfiguredNameResolverInfoByKey = (\n account: any,\n): Record<string, NameResolverInfo> => {\n const infoByKey: Record<string, NameResolverInfo> = {};\n\n for (const provider of getConfiguredEthNameResolverProviders(account)) {\n if (!isSupportedBsoResolverProvider(provider)) {\n continue;\n }\n\n const providerLabel = getNameResolverProviderLabel(provider);\n const key = `eth-${providerLabel}`;\n\n if (!infoByKey[key]) {\n infoByKey[key] = {\n key,\n nameSystem: \"eth\",\n chainTicker: \"eth\",\n provider,\n providerLabel,\n };\n }\n }\n\n return infoByKey;\n};\n\nexport const getMatchingNameResolvers = (account: any, address?: string): NameResolverInfo[] => {\n if (!isEthAliasDomain(address)) {\n return [];\n }\n\n return Object.values(getConfiguredNameResolverInfoByKey(account));\n};\n\nconst buildConfiguredNameResolvers = (account: any, dataPath?: string) =>\n Object.values(getConfiguredNameResolverInfoByKey(account)).map(\n (resolverInfo) =>\n new BsoResolver({\n key: resolverInfo.key,\n provider: resolverInfo.provider,\n dataPath,\n }),\n );\n\nexport const resolveAuthorNameWithProtocol = (\n protocolClient: any,\n options: { address?: string } | Record<string, any>,\n) => {\n const resolveAuthorName =\n protocolClient?.resolveAuthorAddress || protocolClient?.resolveAuthorName;\n assert(\n typeof resolveAuthorName === \"function\",\n \"protocol client resolveAuthorName/resolveAuthorAddress missing\",\n );\n return resolveAuthorName.call(protocolClient, options);\n};\n\nexport const normalizeOptionsForPkcClient = <T extends Record<string, any> | undefined>(\n options: T,\n): T => {\n if (!options) {\n return options;\n }\n\n const normalized: Record<string, any> = { ...options };\n\n if (normalized.resolveAuthorNames == null && normalized.resolveAuthorAddresses != null) {\n normalized.resolveAuthorNames = normalized.resolveAuthorAddresses;\n }\n\n delete normalized.resolveAuthorAddresses;\n delete normalized.chainProviders;\n delete normalized.nameResolversChainProviders;\n\n return normalized as T;\n};\n\nexport const getPkcClientOptions = <T extends Record<string, any> | undefined>(\n account: any,\n options: T,\n): T => {\n const normalized = normalizeOptionsForPkcClient(options);\n\n if (!normalized) {\n return normalized;\n }\n\n const nameResolvers = buildConfiguredNameResolvers(account, normalized.dataPath);\n if (nameResolvers.length) {\n normalized.nameResolvers = nameResolvers;\n }\n\n return normalized as T;\n};\n\nexport const normalizeAccountProtocolConfig = <T extends Record<string, any> | undefined>(\n account: T,\n defaultChainProviders?: Record<string, any>,\n): T => {\n if (!account) {\n return account;\n }\n\n const nextAccount: Record<string, any> = { ...account };\n const protocolOptions =\n nextAccount.pkcOptions && typeof nextAccount.pkcOptions === \"object\"\n ? { ...nextAccount.pkcOptions }\n : nextAccount.pkcOptions;\n\n const chainProviders =\n nextAccount.chainProviders || protocolOptions?.chainProviders || defaultChainProviders;\n if (chainProviders !== undefined) {\n nextAccount.chainProviders = chainProviders;\n }\n\n if (\n nextAccount.nameResolversChainProviders === undefined &&\n protocolOptions?.nameResolversChainProviders !== undefined\n ) {\n nextAccount.nameResolversChainProviders = protocolOptions.nameResolversChainProviders;\n }\n\n if (protocolOptions && typeof protocolOptions === \"object\") {\n delete protocolOptions.chainProviders;\n delete protocolOptions.nameResolversChainProviders;\n nextAccount.pkcOptions = protocolOptions;\n }\n\n return nextAccount as T;\n};\n\nexport const withProtocolAliases = <T extends Record<string, any>>(\n account: T,\n protocolClient?: any,\n protocolOptions?: any,\n): T => {\n const nextAccount: Record<string, any> = { ...account };\n\n if (protocolClient !== undefined) {\n nextAccount.pkc = protocolClient;\n }\n if (protocolOptions !== undefined) {\n nextAccount.pkcOptions = protocolOptions;\n }\n\n return nextAccount as T;\n};\n\nexport * from \"./protocol-compat\";\n"]}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
declare const markdownExample = "# h1 Heading 8-)\n## h2 Heading\n### h3 Heading\n#### h4 Heading\n##### h5 Heading\n###### h6 Heading\n\n\n## Horizontal Rules\n\n___\n\n---\n\n***\n\n\n## Typographic replacements\n\nEnable typographer option to see result.\n\n(c) (C) (r) (R) (tm) (TM) (p) (P) +-\n\ntest.. test... test..... test?..... test!....\n\n!!!!!! ???? ,, -- ---\n\n\"Smartypants, double quotes\" and 'single quotes'\n\n\n## Emphasis\n\n**This is bold text**\n\n__This is bold text__\n\n*This is italic text*\n\n_This is italic text_\n\n~~Strikethrough~~\n\n\n## Blockquotes\n\n\n> Blockquotes can also be nested...\n>> ...by using additional greater-than signs right next to each other...\n> > > ...or with spaces between arrows.\n\n\n## Lists\n\nUnordered\n\n+ Create a list by starting a line with `+`, `-`, or `*`\n+ Sub-lists are made by indenting 2 spaces:\n - Marker character change forces new list start:\n * Ac tristique libero volutpat at\n + Facilisis in pretium nisl aliquet\n - Nulla volutpat aliquam velit\n+ Very easy!\n\nOrdered\n\n1. Lorem ipsum dolor sit amet\n2. Consectetur adipiscing elit\n3. Integer molestie lorem at massa\n\n\n1. You can use sequential numbers...\n1. ...or keep all the numbers as `1.`\n\nStart numbering with offset:\n\n57. foo\n1. bar\n\n\n## Code\n\nInline `code`\n\nIndented code\n\n // Some comments\n line 1 of code\n line 2 of code\n line 3 of code\n\n\nBlock code \"fences\"\n\n```\nSample text here...\n```\n\nSyntax highlighting\n\n``` js\nvar foo = function (bar) {\n return bar++;\n};\n\nconsole.log(foo(5));\n```\n\n## Tables\n\n| Option | Description |\n| ------ | ----------- |\n| data | path to data files to supply the data that will be passed into templates. |\n| engine | engine to be used for processing templates. Handlebars is the default. |\n| ext | extension to be used for dest files. |\n\nRight aligned columns\n\n| Option | Description |\n| ------:| -----------:|\n| data | path to data files to supply the data that will be passed into templates. |\n| engine | engine to be used for processing templates. Handlebars is the default. |\n| ext | extension to be used for dest files. |\n\n\n## Links\n\n[link text](http://dev.nodeca.com)\n\n[link with title](http://nodeca.github.io/pica/demo/ \"title text!\")\n\nAutoconverted link https://github.com/nodeca/pica (enable linkify to see)\n\n\n## Images\n\n\n\n\nLike links, Images also have a footnote style syntax\n\n![Alt text][id]\n\nWith a reference later in the document defining the URL location:\n\n[id]: https://octodex.github.com/images/dojocat.jpg \"The Dojocat\"\n\n\n## Plugins\n\nThe killer feature of `markdown-it` is very effective support of\n[syntax plugins](https://www.npmjs.org/browse/keyword/markdown-it-plugin).\n\n\n### [Emojies](https://github.com/markdown-it/markdown-it-emoji)\n\n> Classic markup: :wink: :crush: :cry: :tear: :laughing: :yum:\n>\n> Shortcuts (emoticons): :-) :-( 8-) ;)\n\nsee [how to change output](https://github.com/markdown-it/markdown-it-emoji#change-output) with twemoji.\n\n\n### [Subscript](https://github.com/markdown-it/markdown-it-sub) / [Superscript](https://github.com/markdown-it/markdown-it-sup)\n\n- 19^th^\n- H~2~O\n\n\n### [<ins>](https://github.com/markdown-it/markdown-it-ins)\n\n++Inserted text++\n\n\n### [<mark>](https://github.com/markdown-it/markdown-it-mark)\n\n==Marked text==\n\n\n### [Footnotes](https://github.com/markdown-it/markdown-it-footnote)\n\nFootnote 1 link[^first].\n\nFootnote 2 link[^second].\n\nInline footnote^[Text of inline footnote] definition.\n\nDuplicated footnote reference[^second].\n\n[^first]: Footnote **can have markup**\n\n and multiple paragraphs.\n\n[^second]: Footnote text.\n\n\n### [Definition lists](https://github.com/markdown-it/markdown-it-deflist)\n\nTerm 1\n\n: Definition 1\nwith lazy continuation.\n\nTerm 2 with *inline markup*\n\n: Definition 2\n\n { some code, part of Definition 2 }\n\n Third paragraph of definition 2.\n\n_Compact style:_\n\nTerm 1\n ~ Definition 1\n\nTerm 2\n ~ Definition 2a\n ~ Definition 2b\n\n\n### [Abbreviations](https://github.com/markdown-it/markdown-it-abbr)\n\nThis is HTML abbreviation example.\n\nIt converts \"HTML\", but keep intact partial entries like \"xxxHTMLyyy\" and so on.\n\n*[HTML]: Hyper Text Markup Language\n\n### [Custom containers](https://github.com/markdown-it/markdown-it-container)\n\n::: warning\n*here be dragons*\n:::\n\n## XSS from https://github.com/cujanovic/Markdown-XSS-Payloads\n\n[a](javascript:prompt(document.cookie))\n[a](j a v a s c r i p t:prompt(document.cookie))\n)\\\n<javascript:prompt(document.cookie)>\n<javascript:alert('XSS')>\n\\\n[a](data:text/html;base64,PHNjcmlwdD5hbGVydCgnWFNTJyk8L3NjcmlwdD4K)\n[a](javascript:alert('XSS'))\n\\\n[citelol]: (javascript:prompt(document.cookie))\n[notmalicious](javascript:window.onerror=alert;throw%20document.cookie)\n[test](javascript://%0d%0aprompt(1))\n[test](javascript://%0d%0aprompt(1);com)\n[notmalicious](javascript:window.onerror=alert;throw%20document.cookie)\n[notmalicious](javascript://%0d%0awindow.onerror=alert;throw%20document.cookie)\n[a](data:text/html;base64,PHNjcmlwdD5hbGVydCgnWFNTJyk8L3NjcmlwdD4K)\n[clickme](vbscript:alert(document.domain))\n_http://danlec_@.1 style=background-image:url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAIAAAABACAMAAADlCI9NAAACcFBMVEX/AAD//////f3//v7/0tL/AQH/cHD/Cwv/+/v/CQn/EBD/FRX/+Pj/ISH/PDz/6Oj/CAj/FBT/DAz/Bgb/rq7/p6f/gID/mpr/oaH/NTX/5+f/mZn/wcH/ICD/ERH/Skr/3Nz/AgL/trb/QED/z8//6+v/BAT/i4v/9fX/ZWX/x8f/aGj/ysr/8/P/UlL/8vL/T0//dXX/hIT/eXn/bGz/iIj/XV3/jo7/W1v/wMD/Hh7/+vr/t7f/1dX/HBz/zc3/nJz/4eH/Zmb/Hx//RET/Njb/jIz/f3//Ojr/w8P/Ghr/8PD/Jyf/mJj/AwP/srL/Cgr/1NT/5ub/PT3/fHz/Dw//eHj/ra3/IiL/DQ3//Pz/9/f/Ly//+fn/UFD/MTH/vb3/7Oz/pKT/1tb/2tr/jY3/6en/QkL/5OT/ubn/JSX/MjL/Kyv/Fxf/Rkb/sbH/39//iYn/q6v/qqr/Y2P/Li7/wsL/uLj/4+P/yMj/S0v/GRn/cnL/hob/l5f/s7P/Tk7/WVn/ior/09P/hYX/bW3/GBj/XFz/aWn/Q0P/vLz/KCj/kZH/5eX/U1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EXplvA/bCR2JXAYMSawtkiqfaDHjNtYVfhzJJBvBGJ3zmADhv6054W71ZrBNvHZDigr0DDCcFkHeB8wog70G/2LXA+xIrh03i02Zgavx0Blo+SA5Q+yEcrVSAYvjYBhwEPrEoDZ+KX20wIe7G1ZtwTJIDyMYU+FwBeuGLpaLqg91NcqnqgQU9Yre/ETpzkwXIIKAAmRnQruboUeiVS1cHmF8pcv70bqBVkgak1tgAaYbuw9bj9kFjVN28wsJvxK9VFQDGzjVF7d9+9z1ARJIHyMxRQNo2SDn2408HBsY5njZJPcFbTomJo59H5HIAUmIDpPQXVGS0igfg7detBqptv/0ulwfIbbQB8kchVtNmiQsQUO7Qru37jpQX7WmS/6YZPXP+LPprbVgC0ul0Op1Op9Pp/gYrAa7fWhG7QQAAAABJRU5ErkJggg==);background-repeat:no-repeat;display:block;width:100%;height:100px; onclick=alert(unescape(/Oh%20No!/.source));return(false);//\n<http://\\<meta\\ http-equiv=\\\"refresh\\\"\\ content=\\\"0;\\ url=http://danlec.com/\\\"\\>>\n[text](http://danlec.com \" [@danlec](/danlec) \")\n[a](javascript:this;alert(1))\n[a](javascript:this;alert(1))\n[a](javascript:this;alert(1))\n[a](Javascript:alert(1))\n[a](Javas%26%2399;ript:alert(1))\n[a](javascript:alert(1))\n[a](javascript:confirm(1)\n[a](javascript://www.google.com%0Aprompt(1))\n[a](javascript://%0d%0aconfirm(1);com)\n[a](javascript:window.onerror=confirm;throw%201)\n[a](\u0001javascript:alert(document.domain))\n[a](javascript://www.google.com%0Aalert(1))\n[a]('javascript:alert(\"1\")')\n[a](JaVaScRiPt:alert(1))\n)\n)\n</http://<?php\\><\\h1\\><script:script>confirm(2)\n[XSS](.alert(1);)\n[ ](https://a.de?p=[[/data-x=. style=background-color:#000000;z-index:999;width:100%;position:fixed;top:0;left:0;right:0;bottom:0; data-y=.]])\n[ ](http://a?p=[[/onclick=alert(0) .]])\n[a](javascript:new%20Function`al\\ert\\`1\\``;)\n";
|
|
2
|
+
export default markdownExample;
|
|
3
|
+
//# sourceMappingURL=markdown-example.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"markdown-example.d.ts","sourceRoot":"","sources":["../../../../src/lib/pkc-js/fixtures/markdown-example.ts"],"names":[],"mappings":"AAAA,QAAA,MAAM,eAAe,g7RAqRpB,CAAC;AAEF,eAAe,eAAe,CAAC"}
|
|
@@ -0,0 +1,280 @@
|
|
|
1
|
+
const markdownExample = `# h1 Heading 8-)
|
|
2
|
+
## h2 Heading
|
|
3
|
+
### h3 Heading
|
|
4
|
+
#### h4 Heading
|
|
5
|
+
##### h5 Heading
|
|
6
|
+
###### h6 Heading
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
## Horizontal Rules
|
|
10
|
+
|
|
11
|
+
___
|
|
12
|
+
|
|
13
|
+
---
|
|
14
|
+
|
|
15
|
+
***
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
## Typographic replacements
|
|
19
|
+
|
|
20
|
+
Enable typographer option to see result.
|
|
21
|
+
|
|
22
|
+
(c) (C) (r) (R) (tm) (TM) (p) (P) +-
|
|
23
|
+
|
|
24
|
+
test.. test... test..... test?..... test!....
|
|
25
|
+
|
|
26
|
+
!!!!!! ???? ,, -- ---
|
|
27
|
+
|
|
28
|
+
"Smartypants, double quotes" and 'single quotes'
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
## Emphasis
|
|
32
|
+
|
|
33
|
+
**This is bold text**
|
|
34
|
+
|
|
35
|
+
__This is bold text__
|
|
36
|
+
|
|
37
|
+
*This is italic text*
|
|
38
|
+
|
|
39
|
+
_This is italic text_
|
|
40
|
+
|
|
41
|
+
~~Strikethrough~~
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
## Blockquotes
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
> Blockquotes can also be nested...
|
|
48
|
+
>> ...by using additional greater-than signs right next to each other...
|
|
49
|
+
> > > ...or with spaces between arrows.
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
## Lists
|
|
53
|
+
|
|
54
|
+
Unordered
|
|
55
|
+
|
|
56
|
+
+ Create a list by starting a line with \`+\`, \`-\`, or \`*\`
|
|
57
|
+
+ Sub-lists are made by indenting 2 spaces:
|
|
58
|
+
- Marker character change forces new list start:
|
|
59
|
+
* Ac tristique libero volutpat at
|
|
60
|
+
+ Facilisis in pretium nisl aliquet
|
|
61
|
+
- Nulla volutpat aliquam velit
|
|
62
|
+
+ Very easy!
|
|
63
|
+
|
|
64
|
+
Ordered
|
|
65
|
+
|
|
66
|
+
1. Lorem ipsum dolor sit amet
|
|
67
|
+
2. Consectetur adipiscing elit
|
|
68
|
+
3. Integer molestie lorem at massa
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
1. You can use sequential numbers...
|
|
72
|
+
1. ...or keep all the numbers as \`1.\`
|
|
73
|
+
|
|
74
|
+
Start numbering with offset:
|
|
75
|
+
|
|
76
|
+
57. foo
|
|
77
|
+
1. bar
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
## Code
|
|
81
|
+
|
|
82
|
+
Inline \`code\`
|
|
83
|
+
|
|
84
|
+
Indented code
|
|
85
|
+
|
|
86
|
+
// Some comments
|
|
87
|
+
line 1 of code
|
|
88
|
+
line 2 of code
|
|
89
|
+
line 3 of code
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
Block code "fences"
|
|
93
|
+
|
|
94
|
+
\`\`\`
|
|
95
|
+
Sample text here...
|
|
96
|
+
\`\`\`
|
|
97
|
+
|
|
98
|
+
Syntax highlighting
|
|
99
|
+
|
|
100
|
+
\`\`\` js
|
|
101
|
+
var foo = function (bar) {
|
|
102
|
+
return bar++;
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
console.log(foo(5));
|
|
106
|
+
\`\`\`
|
|
107
|
+
|
|
108
|
+
## Tables
|
|
109
|
+
|
|
110
|
+
| Option | Description |
|
|
111
|
+
| ------ | ----------- |
|
|
112
|
+
| data | path to data files to supply the data that will be passed into templates. |
|
|
113
|
+
| engine | engine to be used for processing templates. Handlebars is the default. |
|
|
114
|
+
| ext | extension to be used for dest files. |
|
|
115
|
+
|
|
116
|
+
Right aligned columns
|
|
117
|
+
|
|
118
|
+
| Option | Description |
|
|
119
|
+
| ------:| -----------:|
|
|
120
|
+
| data | path to data files to supply the data that will be passed into templates. |
|
|
121
|
+
| engine | engine to be used for processing templates. Handlebars is the default. |
|
|
122
|
+
| ext | extension to be used for dest files. |
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
## Links
|
|
126
|
+
|
|
127
|
+
[link text](http://dev.nodeca.com)
|
|
128
|
+
|
|
129
|
+
[link with title](http://nodeca.github.io/pica/demo/ "title text!")
|
|
130
|
+
|
|
131
|
+
Autoconverted link https://github.com/nodeca/pica (enable linkify to see)
|
|
132
|
+
|
|
133
|
+
|
|
134
|
+
## Images
|
|
135
|
+
|
|
136
|
+

|
|
137
|
+

|
|
138
|
+
|
|
139
|
+
Like links, Images also have a footnote style syntax
|
|
140
|
+
|
|
141
|
+
![Alt text][id]
|
|
142
|
+
|
|
143
|
+
With a reference later in the document defining the URL location:
|
|
144
|
+
|
|
145
|
+
[id]: https://octodex.github.com/images/dojocat.jpg "The Dojocat"
|
|
146
|
+
|
|
147
|
+
|
|
148
|
+
## Plugins
|
|
149
|
+
|
|
150
|
+
The killer feature of \`markdown-it\` is very effective support of
|
|
151
|
+
[syntax plugins](https://www.npmjs.org/browse/keyword/markdown-it-plugin).
|
|
152
|
+
|
|
153
|
+
|
|
154
|
+
### [Emojies](https://github.com/markdown-it/markdown-it-emoji)
|
|
155
|
+
|
|
156
|
+
> Classic markup: :wink: :crush: :cry: :tear: :laughing: :yum:
|
|
157
|
+
>
|
|
158
|
+
> Shortcuts (emoticons): :-) :-( 8-) ;)
|
|
159
|
+
|
|
160
|
+
see [how to change output](https://github.com/markdown-it/markdown-it-emoji#change-output) with twemoji.
|
|
161
|
+
|
|
162
|
+
|
|
163
|
+
### [Subscript](https://github.com/markdown-it/markdown-it-sub) / [Superscript](https://github.com/markdown-it/markdown-it-sup)
|
|
164
|
+
|
|
165
|
+
- 19^th^
|
|
166
|
+
- H~2~O
|
|
167
|
+
|
|
168
|
+
|
|
169
|
+
### [\<ins>](https://github.com/markdown-it/markdown-it-ins)
|
|
170
|
+
|
|
171
|
+
++Inserted text++
|
|
172
|
+
|
|
173
|
+
|
|
174
|
+
### [\<mark>](https://github.com/markdown-it/markdown-it-mark)
|
|
175
|
+
|
|
176
|
+
==Marked text==
|
|
177
|
+
|
|
178
|
+
|
|
179
|
+
### [Footnotes](https://github.com/markdown-it/markdown-it-footnote)
|
|
180
|
+
|
|
181
|
+
Footnote 1 link[^first].
|
|
182
|
+
|
|
183
|
+
Footnote 2 link[^second].
|
|
184
|
+
|
|
185
|
+
Inline footnote^[Text of inline footnote] definition.
|
|
186
|
+
|
|
187
|
+
Duplicated footnote reference[^second].
|
|
188
|
+
|
|
189
|
+
[^first]: Footnote **can have markup**
|
|
190
|
+
|
|
191
|
+
and multiple paragraphs.
|
|
192
|
+
|
|
193
|
+
[^second]: Footnote text.
|
|
194
|
+
|
|
195
|
+
|
|
196
|
+
### [Definition lists](https://github.com/markdown-it/markdown-it-deflist)
|
|
197
|
+
|
|
198
|
+
Term 1
|
|
199
|
+
|
|
200
|
+
: Definition 1
|
|
201
|
+
with lazy continuation.
|
|
202
|
+
|
|
203
|
+
Term 2 with *inline markup*
|
|
204
|
+
|
|
205
|
+
: Definition 2
|
|
206
|
+
|
|
207
|
+
{ some code, part of Definition 2 }
|
|
208
|
+
|
|
209
|
+
Third paragraph of definition 2.
|
|
210
|
+
|
|
211
|
+
_Compact style:_
|
|
212
|
+
|
|
213
|
+
Term 1
|
|
214
|
+
~ Definition 1
|
|
215
|
+
|
|
216
|
+
Term 2
|
|
217
|
+
~ Definition 2a
|
|
218
|
+
~ Definition 2b
|
|
219
|
+
|
|
220
|
+
|
|
221
|
+
### [Abbreviations](https://github.com/markdown-it/markdown-it-abbr)
|
|
222
|
+
|
|
223
|
+
This is HTML abbreviation example.
|
|
224
|
+
|
|
225
|
+
It converts "HTML", but keep intact partial entries like "xxxHTMLyyy" and so on.
|
|
226
|
+
|
|
227
|
+
*[HTML]: Hyper Text Markup Language
|
|
228
|
+
|
|
229
|
+
### [Custom containers](https://github.com/markdown-it/markdown-it-container)
|
|
230
|
+
|
|
231
|
+
::: warning
|
|
232
|
+
*here be dragons*
|
|
233
|
+
:::
|
|
234
|
+
|
|
235
|
+
## XSS from https://github.com/cujanovic/Markdown-XSS-Payloads
|
|
236
|
+
|
|
237
|
+
[a](javascript:prompt(document.cookie))
|
|
238
|
+
[a](j a v a s c r i p t:prompt(document.cookie))
|
|
239
|
+
)\\
|
|
240
|
+
<javascript:prompt(document.cookie)>
|
|
241
|
+
<javascript:alert('XSS')>
|
|
242
|
+
\\
|
|
243
|
+
[a](data:text/html;base64,PHNjcmlwdD5hbGVydCgnWFNTJyk8L3NjcmlwdD4K)
|
|
244
|
+
[a](javascript:alert('XSS'))
|
|
245
|
+
\\
|
|
246
|
+
[citelol]: (javascript:prompt(document.cookie))
|
|
247
|
+
[notmalicious](javascript:window.onerror=alert;throw%20document.cookie)
|
|
248
|
+
[test](javascript://%0d%0aprompt(1))
|
|
249
|
+
[test](javascript://%0d%0aprompt(1);com)
|
|
250
|
+
[notmalicious](javascript:window.onerror=alert;throw%20document.cookie)
|
|
251
|
+
[notmalicious](javascript://%0d%0awindow.onerror=alert;throw%20document.cookie)
|
|
252
|
+
[a](data:text/html;base64,PHNjcmlwdD5hbGVydCgnWFNTJyk8L3NjcmlwdD4K)
|
|
253
|
+
[clickme](vbscript:alert(document.domain))
|
|
254
|
+
_http://danlec_@.1 style=background-image:url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAIAAAABACAMAAADlCI9NAAACcFBMVEX/AAD//////f3//v7/0tL/AQH/cHD/Cwv/+/v/CQn/EBD/FRX/+Pj/ISH/PDz/6Oj/CAj/FBT/DAz/Bgb/rq7/p6f/gID/mpr/oaH/N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nJsXALj/Hpiy2B9wofqW9AQAg8Bd8VOpCR02YMVEE4xli/L8AOmtQMQHsP9IGUBZedq/AWJfIez+x4KZqgDtBlbzon6A8GnonOwBXNONavlmUS2Dx8XTjcCwe1wNvGQB2gxaKhbV7Ubx3QC5bRMUuAEvA9kFzzW3TQAeVoB5cFw8zQUGPH9M4LwFgML5IpL6BHCvH0DmAD3xgIUpUJcTmy7UQHaV/bteKZ6GgGr3eAq4QQEmWlNqJ1z0BeTvgGfz4gAFsDXfUmbeAeoAF0OfuLL8C91jHnCtBchYq7YzsMsXIFkmDDsBjwBfi2o6GM9IrOshIp5mA6vc42Sg1wJMEVUJlPgDpBzWb3EAVsMOm5m7Hg5KrAjcJJ5uRn3uLAvosgBrRPUgnAgApC2HjtpRwFTneZRpqLs6Ak+Lp5lAj9+LccoCzLYPZjBA3gIGRgHj4EuxewH6JdZhKBVPM4CL7rEIiKo7kMAvILIEXplvA/bCR2JXAYMSawtkiqfaDHjNtYVfhzJJBvBGJ3zmADhv6054W71ZrBNvHZDigr0DDCcFkHeB8wog70G/2LXA+xIrh03i02Zgavx0Blo+SA5Q+yEcrVSAYvjYBhwEPrEoDZ+KX20wIe7G1ZtwTJIDyMYU+FwBeuGLpaLqg91NcqnqgQU9Yre/ETpzkwXIIKAAmRnQruboUeiVS1cHmF8pcv70bqBVkgak1tgAaYbuw9bj9kFjVN28wsJvxK9VFQDGzjVF7d9+9z1ARJIHyMxRQNo2SDn2408HBsY5njZJPcFbTomJo59H5HIAUmIDpPQXVGS0igfg7detBqptv/0ulwfIbbQB8kchVtNmiQsQUO7Qru37jpQX7WmS/6YZPXP+LPprbVgC0ul0Op1Op9Pp/gYrAa7fWhG7QQAAAABJRU5ErkJggg==);background-repeat:no-repeat;display:block;width:100%;height:100px; onclick=alert(unescape(/Oh%20No!/.source));return(false);//
|
|
255
|
+
<http://\\<meta\\ http-equiv=\\"refresh\\"\\ content=\\"0;\\ url=http://danlec.com/\\"\\>>
|
|
256
|
+
[text](http://danlec.com " [@danlec](/danlec) ")
|
|
257
|
+
[a](javascript:this;alert(1))
|
|
258
|
+
[a](javascript:this;alert(1))
|
|
259
|
+
[a](javascript:this;alert(1))
|
|
260
|
+
[a](Javascript:alert(1))
|
|
261
|
+
[a](Javas%26%2399;ript:alert(1))
|
|
262
|
+
[a](javascript:alert(1))
|
|
263
|
+
[a](javascript:confirm(1)
|
|
264
|
+
[a](javascript://www.google.com%0Aprompt(1))
|
|
265
|
+
[a](javascript://%0d%0aconfirm(1);com)
|
|
266
|
+
[a](javascript:window.onerror=confirm;throw%201)
|
|
267
|
+
[a](javascript:alert(document.domain))
|
|
268
|
+
[a](javascript://www.google.com%0Aalert(1))
|
|
269
|
+
[a]('javascript:alert("1")')
|
|
270
|
+
[a](JaVaScRiPt:alert(1))
|
|
271
|
+
)
|
|
272
|
+
)
|
|
273
|
+
</http://<?php\\><\\h1\\><script:script>confirm(2)
|
|
274
|
+
[XSS](.alert(1);)
|
|
275
|
+
[ ](https://a.de?p=[[/data-x=. style=background-color:#000000;z-index:999;width:100%;position:fixed;top:0;left:0;right:0;bottom:0; data-y=.]])
|
|
276
|
+
[ ](http://a?p=[[/onclick=alert(0) .]])
|
|
277
|
+
[a](javascript:new%20Function\`al\\ert\\\`1\\\`\`;)
|
|
278
|
+
`;
|
|
279
|
+
export default markdownExample;
|
|
280
|
+
//# sourceMappingURL=markdown-example.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"markdown-example.js","sourceRoot":"","sources":["../../../../src/lib/pkc-js/fixtures/markdown-example.ts"],"names":[],"mappings":"AAAA,MAAM,eAAe,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAqRvB,CAAC;AAEF,eAAe,eAAe,CAAC","sourcesContent":["const markdownExample = `# h1 Heading 8-)\n## h2 Heading\n### h3 Heading\n#### h4 Heading\n##### h5 Heading\n###### h6 Heading\n\n\n## Horizontal Rules\n\n___\n\n---\n\n***\n\n\n## Typographic replacements\n\nEnable typographer option to see result.\n\n(c) (C) (r) (R) (tm) (TM) (p) (P) +-\n\ntest.. test... test..... test?..... test!....\n\n!!!!!! ???? ,, -- ---\n\n\"Smartypants, double quotes\" and 'single quotes'\n\n\n## Emphasis\n\n**This is bold text**\n\n__This is bold text__\n\n*This is italic text*\n\n_This is italic text_\n\n~~Strikethrough~~\n\n\n## Blockquotes\n\n\n> Blockquotes can also be nested...\n>> ...by using additional greater-than signs right next to each other...\n> > > ...or with spaces between arrows.\n\n\n## Lists\n\nUnordered\n\n+ Create a list by starting a line with \\`+\\`, \\`-\\`, or \\`*\\`\n+ Sub-lists are made by indenting 2 spaces:\n - Marker character change forces new list start:\n * Ac tristique libero volutpat at\n + Facilisis in pretium nisl aliquet\n - Nulla volutpat aliquam velit\n+ Very easy!\n\nOrdered\n\n1. Lorem ipsum dolor sit amet\n2. Consectetur adipiscing elit\n3. Integer molestie lorem at massa\n\n\n1. You can use sequential numbers...\n1. ...or keep all the numbers as \\`1.\\`\n\nStart numbering with offset:\n\n57. foo\n1. bar\n\n\n## Code\n\nInline \\`code\\`\n\nIndented code\n\n // Some comments\n line 1 of code\n line 2 of code\n line 3 of code\n\n\nBlock code \"fences\"\n\n\\`\\`\\`\nSample text here...\n\\`\\`\\`\n\nSyntax highlighting\n\n\\`\\`\\` js\nvar foo = function (bar) {\n return bar++;\n};\n\nconsole.log(foo(5));\n\\`\\`\\`\n\n## Tables\n\n| Option | Description |\n| ------ | ----------- |\n| data | path to data files to supply the data that will be passed into templates. |\n| engine | engine to be used for processing templates. Handlebars is the default. |\n| ext | extension to be used for dest files. |\n\nRight aligned columns\n\n| Option | Description |\n| ------:| -----------:|\n| data | path to data files to supply the data that will be passed into templates. |\n| engine | engine to be used for processing templates. Handlebars is the default. |\n| ext | extension to be used for dest files. |\n\n\n## Links\n\n[link text](http://dev.nodeca.com)\n\n[link with title](http://nodeca.github.io/pica/demo/ \"title text!\")\n\nAutoconverted link https://github.com/nodeca/pica (enable linkify to see)\n\n\n## Images\n\n\n\n\nLike links, Images also have a footnote style syntax\n\n![Alt text][id]\n\nWith a reference later in the document defining the URL location:\n\n[id]: https://octodex.github.com/images/dojocat.jpg \"The Dojocat\"\n\n\n## Plugins\n\nThe killer feature of \\`markdown-it\\` is very effective support of\n[syntax plugins](https://www.npmjs.org/browse/keyword/markdown-it-plugin).\n\n\n### [Emojies](https://github.com/markdown-it/markdown-it-emoji)\n\n> Classic markup: :wink: :crush: :cry: :tear: :laughing: :yum:\n>\n> Shortcuts (emoticons): :-) :-( 8-) ;)\n\nsee [how to change output](https://github.com/markdown-it/markdown-it-emoji#change-output) with twemoji.\n\n\n### [Subscript](https://github.com/markdown-it/markdown-it-sub) / [Superscript](https://github.com/markdown-it/markdown-it-sup)\n\n- 19^th^\n- H~2~O\n\n\n### [\\<ins>](https://github.com/markdown-it/markdown-it-ins)\n\n++Inserted text++\n\n\n### [\\<mark>](https://github.com/markdown-it/markdown-it-mark)\n\n==Marked text==\n\n\n### [Footnotes](https://github.com/markdown-it/markdown-it-footnote)\n\nFootnote 1 link[^first].\n\nFootnote 2 link[^second].\n\nInline footnote^[Text of inline footnote] definition.\n\nDuplicated footnote reference[^second].\n\n[^first]: Footnote **can have markup**\n\n and multiple paragraphs.\n\n[^second]: Footnote text.\n\n\n### [Definition lists](https://github.com/markdown-it/markdown-it-deflist)\n\nTerm 1\n\n: Definition 1\nwith lazy continuation.\n\nTerm 2 with *inline markup*\n\n: Definition 2\n\n { some code, part of Definition 2 }\n\n Third paragraph of definition 2.\n\n_Compact style:_\n\nTerm 1\n ~ Definition 1\n\nTerm 2\n ~ Definition 2a\n ~ Definition 2b\n\n\n### [Abbreviations](https://github.com/markdown-it/markdown-it-abbr)\n\nThis is HTML abbreviation example.\n\nIt converts \"HTML\", but keep intact partial entries like \"xxxHTMLyyy\" and so on.\n\n*[HTML]: Hyper Text Markup Language\n\n### [Custom containers](https://github.com/markdown-it/markdown-it-container)\n\n::: warning\n*here be dragons*\n:::\n\n## XSS from https://github.com/cujanovic/Markdown-XSS-Payloads\n\n[a](javascript:prompt(document.cookie))\n[a](j a v a s c r i p t:prompt(document.cookie))\n)\\\\\n<javascript:prompt(document.cookie)>\n<javascript:alert('XSS')>\n\\\\\n[a](data:text/html;base64,PHNjcmlwdD5hbGVydCgnWFNTJyk8L3NjcmlwdD4K)\n[a](javascript:alert('XSS'))\n\\\\\n[citelol]: (javascript:prompt(document.cookie))\n[notmalicious](javascript:window.onerror=alert;throw%20document.cookie)\n[test](javascript://%0d%0aprompt(1))\n[test](javascript://%0d%0aprompt(1);com)\n[notmalicious](javascript:window.onerror=alert;throw%20document.cookie)\n[notmalicious](javascript://%0d%0awindow.onerror=alert;throw%20document.cookie)\n[a](data:text/html;base64,PHNjcmlwdD5hbGVydCgnWFNTJyk8L3NjcmlwdD4K)\n[clickme](vbscript:alert(document.domain))\n_http://danlec_@.1 style=background-image:url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAIAAAABACAMAAADlCI9NAAACcFBMVEX/AAD//////f3//v7/0tL/AQH/cHD/Cwv/+/v/CQn/EBD/FRX/+Pj/ISH/PDz/6Oj/CAj/FBT/DAz/Bgb/rq7/p6f/gID/mpr/oaH/NTX/5+f/mZn/wcH/ICD/ERH/Skr/3Nz/AgL/trb/QED/z8//6+v/BAT/i4v/9fX/ZWX/x8f/aGj/ysr/8/P/UlL/8vL/T0//dXX/hIT/eXn/bGz/iIj/XV3/jo7/W1v/wMD/Hh7/+vr/t7f/1dX/HBz/zc3/nJz/4eH/Zm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8zQUGPH9M4LwFgML5IpL6BHCvH0DmAD3xgIUpUJcTmy7UQHaV/bteKZ6GgGr3eAq4QQEmWlNqJ1z0BeTvgGfz4gAFsDXfUmbeAeoAF0OfuLL8C91jHnCtBchYq7YzsMsXIFkmDDsBjwBfi2o6GM9IrOshIp5mA6vc42Sg1wJMEVUJlPgDpBzWb3EAVsMOm5m7Hg5KrAjcJJ5uRn3uLAvosgBrRPUgnAgApC2HjtpRwFTneZRpqLs6Ak+Lp5lAj9+LccoCzLYPZjBA3gIGRgHj4EuxewH6JdZhKBVPM4CL7rEIiKo7kMAvILIEXplvA/bCR2JXAYMSawtkiqfaDHjNtYVfhzJJBvBGJ3zmADhv6054W71ZrBNvHZDigr0DDCcFkHeB8wog70G/2LXA+xIrh03i02Zgavx0Blo+SA5Q+yEcrVSAYvjYBhwEPrEoDZ+KX20wIe7G1ZtwTJIDyMYU+FwBeuGLpaLqg91NcqnqgQU9Yre/ETpzkwXIIKAAmRnQruboUeiVS1cHmF8pcv70bqBVkgak1tgAaYbuw9bj9kFjVN28wsJvxK9VFQDGzjVF7d9+9z1ARJIHyMxRQNo2SDn2408HBsY5njZJPcFbTomJo59H5HIAUmIDpPQXVGS0igfg7detBqptv/0ulwfIbbQB8kchVtNmiQsQUO7Qru37jpQX7WmS/6YZPXP+LPprbVgC0ul0Op1Op9Pp/gYrAa7fWhG7QQAAAABJRU5ErkJggg==);background-repeat:no-repeat;display:block;width:100%;height:100px; onclick=alert(unescape(/Oh%20No!/.source));return(false);//\n<http://\\\\<meta\\\\ http-equiv=\\\\\"refresh\\\\\"\\\\ content=\\\\\"0;\\\\ url=http://danlec.com/\\\\\"\\\\>>\n[text](http://danlec.com \" [@danlec](/danlec) \")\n[a](javascript:this;alert(1))\n[a](javascript:this;alert(1))\n[a](javascript:this;alert(1))\n[a](Javascript:alert(1))\n[a](Javas%26%2399;ript:alert(1))\n[a](javascript:alert(1))\n[a](javascript:confirm(1)\n[a](javascript://www.google.com%0Aprompt(1))\n[a](javascript://%0d%0aconfirm(1);com)\n[a](javascript:window.onerror=confirm;throw%201)\n[a](\u0001javascript:alert(document.domain))\n[a](javascript://www.google.com%0Aalert(1))\n[a]('javascript:alert(\"1\")')\n[a](JaVaScRiPt:alert(1))\n)\n)\n</http://<?php\\\\><\\\\h1\\\\><script:script>confirm(2)\n[XSS](.alert(1);)\n[ ](https://a.de?p=[[/data-x=. style=background-color:#000000;z-index:999;width:100%;position:fixed;top:0;left:0;right:0;bottom:0; data-y=.]])\n[ ](http://a?p=[[/onclick=alert(0) .]])\n[a](javascript:new%20Function\\`al\\\\ert\\\\\\`1\\\\\\`\\`;)\n`;\n\nexport default markdownExample;\n"]}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
declare const protocolClient: any;
|
|
2
|
+
/**
|
|
3
|
+
* Replace the underlying protocol client with a different implementation, for
|
|
4
|
+
* example to mock it during unit tests, to add mock content
|
|
5
|
+
* for developing the front-end or to add a PKC-compatible client with
|
|
6
|
+
* desktop privileges in the Electron build.
|
|
7
|
+
*/
|
|
8
|
+
export declare function setPkcJs(_PKC: any): void;
|
|
9
|
+
export declare function restorePkcJs(): void;
|
|
10
|
+
export default protocolClient;
|
|
11
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/lib/pkc-js/index.ts"],"names":[],"mappings":"AA8DA,QAAA,MAAM,cAAc,EAAE,GAErB,CAAC;AAEF;;;;;GAKG;AACH,wBAAgB,QAAQ,CAAC,IAAI,EAAE,GAAG,QAIjC;AAED,wBAAgB,YAAY,SAI3B;AASD,eAAe,cAAc,CAAC"}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
// NOTE: don't import pkc-js directly to be able to replace the implementation
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
import PkcJsMockContent from "./pkc-js-mock-content.js";
|
|
12
|
+
import Logger from "@pkcprotocol/pkc-logger";
|
|
13
|
+
import assert from "assert";
|
|
14
|
+
const log = Logger("bitsocial-react-hooks:pkc-js");
|
|
15
|
+
let loadedDefaultPkc;
|
|
16
|
+
const getShortAddressValue = (params = {}) => { var _a; return (_a = params.name) !== null && _a !== void 0 ? _a : params.address; };
|
|
17
|
+
const normalizeShortAddressParams = (params = {}) => {
|
|
18
|
+
const address = getShortAddressValue(params);
|
|
19
|
+
return typeof address === "string" ? Object.assign(Object.assign({}, params), { address, name: address }) : params;
|
|
20
|
+
};
|
|
21
|
+
const getFallbackShortAddress = (params) => {
|
|
22
|
+
const address = getShortAddressValue(params);
|
|
23
|
+
if (typeof address !== "string") {
|
|
24
|
+
return address;
|
|
25
|
+
}
|
|
26
|
+
if (address.includes(".")) {
|
|
27
|
+
return address;
|
|
28
|
+
}
|
|
29
|
+
return address.substring(2, 14);
|
|
30
|
+
};
|
|
31
|
+
const getFallbackShortCid = ({ cid }) => {
|
|
32
|
+
if (typeof cid !== "string") {
|
|
33
|
+
return cid;
|
|
34
|
+
}
|
|
35
|
+
return cid.substring(2, 14);
|
|
36
|
+
};
|
|
37
|
+
const loadDefaultPkc = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
38
|
+
if (!loadedDefaultPkc) {
|
|
39
|
+
const module = yield import("@pkcprotocol/pkc-js");
|
|
40
|
+
loadedDefaultPkc = module.default;
|
|
41
|
+
}
|
|
42
|
+
return loadedDefaultPkc;
|
|
43
|
+
});
|
|
44
|
+
const createLazyDefaultPkc = () => {
|
|
45
|
+
const lazyPkc = (...args) => __awaiter(void 0, void 0, void 0, function* () {
|
|
46
|
+
const PKC = yield loadDefaultPkc();
|
|
47
|
+
return PKC(...args);
|
|
48
|
+
});
|
|
49
|
+
lazyPkc.getShortAddress = (params) => (loadedDefaultPkc === null || loadedDefaultPkc === void 0 ? void 0 : loadedDefaultPkc.getShortAddress)
|
|
50
|
+
? loadedDefaultPkc.getShortAddress(normalizeShortAddressParams(params))
|
|
51
|
+
: getFallbackShortAddress(params);
|
|
52
|
+
lazyPkc.getShortCid = (params) => (loadedDefaultPkc === null || loadedDefaultPkc === void 0 ? void 0 : loadedDefaultPkc.getShortCid)
|
|
53
|
+
? loadedDefaultPkc.getShortCid(params)
|
|
54
|
+
: getFallbackShortCid(params);
|
|
55
|
+
return lazyPkc;
|
|
56
|
+
};
|
|
57
|
+
let defaultPkc = createLazyDefaultPkc();
|
|
58
|
+
const protocolClient = {
|
|
59
|
+
PKC: defaultPkc,
|
|
60
|
+
};
|
|
61
|
+
/**
|
|
62
|
+
* Replace the underlying protocol client with a different implementation, for
|
|
63
|
+
* example to mock it during unit tests, to add mock content
|
|
64
|
+
* for developing the front-end or to add a PKC-compatible client with
|
|
65
|
+
* desktop privileges in the Electron build.
|
|
66
|
+
*/
|
|
67
|
+
export function setPkcJs(_PKC) {
|
|
68
|
+
assert(typeof _PKC === "function", `setPkcJs invalid PKC argument '${_PKC}' not a function`);
|
|
69
|
+
protocolClient.PKC = _PKC;
|
|
70
|
+
log("setPkcJs", _PKC === null || _PKC === void 0 ? void 0 : _PKC.name);
|
|
71
|
+
}
|
|
72
|
+
export function restorePkcJs() {
|
|
73
|
+
defaultPkc = createLazyDefaultPkc();
|
|
74
|
+
protocolClient.PKC = defaultPkc;
|
|
75
|
+
log("restorePkcJs");
|
|
76
|
+
}
|
|
77
|
+
try {
|
|
78
|
+
// mock content for front-end dev with this env var
|
|
79
|
+
if (process.env.REACT_APP_BITSOCIAL_REACT_HOOKS_MOCK_CONTENT) {
|
|
80
|
+
setPkcJs(PkcJsMockContent);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
catch (e) { }
|
|
84
|
+
export default protocolClient;
|
|
85
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/lib/pkc-js/index.ts"],"names":[],"mappings":"AAAA,8EAA8E;;;;;;;;;;AAE9E,OAAO,gBAAgB,MAAM,uBAAuB,CAAC;AACrD,OAAO,MAAM,MAAM,yBAAyB,CAAC;AAC7C,OAAO,MAAM,MAAM,QAAQ,CAAC;AAC5B,MAAM,GAAG,GAAG,MAAM,CAAC,8BAA8B,CAAC,CAAC;AAEnD,IAAI,gBAAqB,CAAC;AAI1B,MAAM,oBAAoB,GAAG,CAAC,SAA6B,EAAE,EAAE,EAAE,WAAC,OAAA,MAAA,MAAM,CAAC,IAAI,mCAAI,MAAM,CAAC,OAAO,CAAA,EAAA,CAAC;AAEhG,MAAM,2BAA2B,GAAG,CAAC,SAA6B,EAAE,EAAE,EAAE;IACtE,MAAM,OAAO,GAAG,oBAAoB,CAAC,MAAM,CAAC,CAAC;IAC7C,OAAO,OAAO,OAAO,KAAK,QAAQ,CAAC,CAAC,iCAAM,MAAM,KAAE,OAAO,EAAE,IAAI,EAAE,OAAO,IAAG,CAAC,CAAC,MAAM,CAAC;AACtF,CAAC,CAAC;AAEF,MAAM,uBAAuB,GAAG,CAAC,MAA0B,EAAE,EAAE;IAC7D,MAAM,OAAO,GAAG,oBAAoB,CAAC,MAAM,CAAC,CAAC;IAC7C,IAAI,OAAO,OAAO,KAAK,QAAQ,EAAE,CAAC;QAChC,OAAO,OAAO,CAAC;IACjB,CAAC;IACD,IAAI,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC;QAC1B,OAAO,OAAO,CAAC;IACjB,CAA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AAC,MAAM,CAAC,CAAC;IAClC,OAAO,OAAO,CAAC;AACjB,CAAC,CAAC;AAEF,IAAI,UAAU,GAAG,oBAAoB,EAAE,CAAC;AAExC,MAAM,cAAc,GAAQ;IAC1B,GAAG,EAAE,UAAU;CAChB,CAAC;AAEF;;;;;GAKG;AACH,MAAM,UAAU,QAAQ,CAAC,IAAS;IAChC,MAAM,CAAC,OAAO,IAAI,KAAK,UAAU,EAAE,kCAAkC,IAAI,kBAAkB,CAAC,CAAC;IAC7F,cAAc,CAAC,GAAG,GAAG,IAAI,CAAC;IAC1B,GAAG,CAAC,UAAU,EAAE,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,IAAI,CAAC,CAAC;AAC9B,CAAC;AAED,MAAM,UAAU,YAAY;IAC1B,UAAU,GAAG,oBAAoB,EAAE,CAAC;IACpC,cAAc,CAAC,GAAG,GAAG,UAAU,CAAC;IAChC,GAAG,CAAC,cAAc,CAAC,CAAC;AACtB,CAAC;AAED,IAAI,CAAC;IACH,mDAAmD;IACnD,IAAI,OAAO,CAAC,GAAG,CAAC,4CAA4C,EAAE,CAAC;QAC7D,QAAQ,CAAC,gBAAgB,CAAC,CAAC;IAC7B,CAAC;AACH,CAAC;AAAC,OAAO,CAAC,EAAE,CAAC,CAAA,CAAC;AAEd,eAAe,cAAc,CAAC","sourcesContent":["// NOTE: don't import pkc-js directly to be able to replace the implementation\n\nimport PkcJsMockContent from \"./pkc-js-mock-content\";\nimport Logger from \"@pkcprotocol/pkc-logger\";\nimport assert from \"assert\";\nconst log = Logger(\"bitsocial-react-hooks:pkc-js\");\n\nlet loadedDefaultPkc: any;\n\ntype ShortAddressParams = { address?: string; name?: string };\n\nconst getShortAddressValue = (params: ShortAddressParams = {}) => params.name ?? params.address;\n\nconst normalizeShortAddressParams = (params: ShortAddressParams = {}) => {\n const address = getShortAddressValue(params);\n return typeof address === \"string\" ? { ...params, address, name: address } : params;\n};\n\nconst getFallbackShortAddress = (params: ShortAddressParams) => {\n const address = getShortAddressValue(params);\n if (typeof address !== \"string\") {\n return address;\n }\n if (address.includes(\".\")) {\n return address;\n }\n return address.substring(2, 14);\n};\n\nconst getFallbackShortCid = ({ cid }: { cid?: string }) => {\n if (typeof cid !== \"string\") {\n return cid;\n }\n return cid.substring(2, 14);\n};\n\nconst loadDefaultPkc = async () => {\n if (!loadedDefaultPkc) {\n const module = await import(\"@pkcprotocol/pkc-js\");\n loadedDefaultPkc = module.default;\n }\n return loadedDefaultPkc;\n};\n\nconst createLazyDefaultPkc = () => {\n const lazyPkc: any = async (...args: any[]) => {\n const PKC = await loadDefaultPkc();\n return PKC(...args);\n };\n lazyPkc.getShortAddress = (params: ShortAddressParams) =>\n loadedDefaultPkc?.getShortAddress\n ? loadedDefaultPkc.getShortAddress(normalizeShortAddressParams(params))\n : getFallbackShortAddress(params);\n lazyPkc.getShortCid = (params: { cid?: string }) =>\n loadedDefaultPkc?.getShortCid\n ? loadedDefaultPkc.getShortCid(params)\n : getFallbackShortCid(params);\n return lazyPkc;\n};\n\nlet defaultPkc = createLazyDefaultPkc();\n\nconst protocolClient: any = {\n PKC: defaultPkc,\n};\n\n/**\n * Replace the underlying protocol client with a different implementation, for\n * example to mock it during unit tests, to add mock content\n * for developing the front-end or to add a PKC-compatible client with\n * desktop privileges in the Electron build.\n */\nexport function setPkcJs(_PKC: any) {\n assert(typeof _PKC === \"function\", `setPkcJs invalid PKC argument '${_PKC}' not a function`);\n protocolClient.PKC = _PKC;\n log(\"setPkcJs\", _PKC?.name);\n}\n\nexport function restorePkcJs() {\n defaultPkc = createLazyDefaultPkc();\n protocolClient.PKC = defaultPkc;\n log(\"restorePkcJs\");\n}\n\ntry {\n // mock content for front-end dev with this env var\n if (process.env.REACT_APP_BITSOCIAL_REACT_HOOKS_MOCK_CONTENT) {\n setPkcJs(PkcJsMockContent);\n }\n} catch (e) {}\n\nexport default protocolClient;\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pkc-js-mock-content.d.ts","sourceRoot":"","sources":["../../../src/lib/pkc-js/pkc-js-mock-content.ts"],"names":[],"mappings":"AAq+CA,QAAA,MAAM,SAAS,EAAE,GAEhB,CAAC;AAeF,eAAe,SAAS,CAAC"}
|