@bitsocial/bitsocial-react-hooks 0.1.2 → 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md
CHANGED
|
@@ -880,19 +880,29 @@ const account = useAccount() // or useAccount('Account 2') to use an account oth
|
|
|
880
880
|
|
|
881
881
|
// `account.author.wallets` only auto-generates an `eth` wallet by default.
|
|
882
882
|
// `account.chainProviders` is the canonical chain config for wallets, NFT lookups, and other chain reads.
|
|
883
|
-
//
|
|
883
|
+
// Defaults use multiple explicit Ethereum RPCs for `.eth` / `.bso` author-name resolution.
|
|
884
|
+
// `account.nameResolversChainProviders` optionally overrides only the RPCs used for that resolution.
|
|
884
885
|
console.log(account.author.wallets.eth)
|
|
885
886
|
|
|
887
|
+
const ethResolverRpcUrls = [
|
|
888
|
+
'https://ethereum-rpc.publicnode.com',
|
|
889
|
+
'https://eth.drpc.org',
|
|
890
|
+
'https://ethereum.publicnode.com',
|
|
891
|
+
'https://rpc.mevblocker.io',
|
|
892
|
+
'https://1rpc.io/eth',
|
|
893
|
+
'https://eth-pokt.nodies.app',
|
|
894
|
+
]
|
|
895
|
+
|
|
886
896
|
const author: {...account.author, displayName: 'John'}
|
|
887
897
|
const editedAccount = {
|
|
888
898
|
...account,
|
|
889
899
|
author,
|
|
890
900
|
chainProviders: {
|
|
891
901
|
...account.chainProviders,
|
|
892
|
-
eth: { urls: [
|
|
902
|
+
eth: { urls: [...ethResolverRpcUrls, 'ethers.js'], chainId: 1 },
|
|
893
903
|
},
|
|
894
904
|
nameResolversChainProviders: {
|
|
895
|
-
eth: { urls:
|
|
905
|
+
eth: { urls: ethResolverRpcUrls, chainId: 1 },
|
|
896
906
|
},
|
|
897
907
|
}
|
|
898
908
|
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { AccountCommunity, ChainProviders } from "../../types.js";
|
|
2
2
|
export declare const DEFAULT_ETH_RPC_URL = "https://ethereum-rpc.publicnode.com";
|
|
3
|
+
export declare const DEFAULT_ETH_RPC_URLS: string[];
|
|
3
4
|
export declare const overwritePkcOptions: {
|
|
4
5
|
resolveAuthorNames: boolean;
|
|
5
6
|
resolveAuthorAddresses: boolean;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"account-generator.d.ts","sourceRoot":"","sources":["../../../src/stores/accounts/account-generator.ts"],"names":[],"mappings":"AAKA,OAAO,EAAY,gBAAgB,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AASzE,eAAO,MAAM,mBAAmB,wCAAwC,CAAC;
|
|
1
|
+
{"version":3,"file":"account-generator.d.ts","sourceRoot":"","sources":["../../../src/stores/accounts/account-generator.ts"],"names":[],"mappings":"AAKA,OAAO,EAAY,gBAAgB,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AASzE,eAAO,MAAM,mBAAmB,wCAAwC,CAAC;AACzE,eAAO,MAAM,oBAAoB,UAOhC,CAAC;AAgBF,eAAO,MAAM,mBAAmB;;;;CAI/B,CAAC;AAqBF,eAAO,MAAM,wBAAwB,QAQd,cACtB,CAAC;AAGF,eAAO,MAAM,oBAAoB;;;CAoChC,CAAC;AAuFF,QAAA,MAAM,gBAAgB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAGrB,CAAC;AAEF,eAAe,gBAAgB,CAAC"}
|
|
@@ -16,11 +16,19 @@ import { getPkcClientOptions, normalizeAccountProtocolConfig, withProtocolAliase
|
|
|
16
16
|
import Logger from "@pkcprotocol/pkc-logger";
|
|
17
17
|
const log = Logger("bitsocial-react-hooks:accounts:stores");
|
|
18
18
|
export const DEFAULT_ETH_RPC_URL = "https://ethereum-rpc.publicnode.com";
|
|
19
|
+
export const DEFAULT_ETH_RPC_URLS = [
|
|
20
|
+
DEFAULT_ETH_RPC_URL,
|
|
21
|
+
"https://eth.drpc.org",
|
|
22
|
+
"https://ethereum.publicnode.com",
|
|
23
|
+
"https://rpc.mevblocker.io",
|
|
24
|
+
"https://1rpc.io/eth",
|
|
25
|
+
"https://eth-pokt.nodies.app",
|
|
26
|
+
];
|
|
19
27
|
// default chain providers
|
|
20
28
|
const chainProviders = {
|
|
21
29
|
eth: {
|
|
22
|
-
//
|
|
23
|
-
urls: [
|
|
30
|
+
// Use explicit RPCs for default name resolution; viem's default transport is opt-in.
|
|
31
|
+
urls: [...DEFAULT_ETH_RPC_URLS, "ethers.js"],
|
|
24
32
|
chainId: 1,
|
|
25
33
|
},
|
|
26
34
|
matic: {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"account-generator.js","sourceRoot":"","sources":["../../../src/stores/accounts/account-generator.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,KAAK,MAAM,kBAAkB,CAAC;AACrC,OAAO,SAAS,MAAM,qBAAqB,CAAC;AAC5C,OAAO,KAAK,MAAM,iBAAiB,CAAC;AACpC,OAAO,EAAE,EAAE,IAAI,IAAI,EAAE,MAAM,MAAM,CAAC;AAClC,OAAO,gBAAgB,MAAM,qBAAqB,CAAC;AAEnD,OAAO,EACL,mBAAmB,EACnB,8BAA8B,EAC9B,mBAAmB,GACpB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,MAAM,MAAM,yBAAyB,CAAC;AAC7C,MAAM,GAAG,GAAG,MAAM,CAAC,uCAAuC,CAAC,CAAC;AAE5D,MAAM,CAAC,MAAM,mBAAmB,GAAG,qCAAqC,CAAC;AAEzE,0BAA0B;AAC1B,MAAM,cAAc,GAAmB;IACrC,GAAG,EAAE;QACH,oEAAoE;QACpE,IAAI,EAAE,CAAC,mBAAmB,EAAE,MAAM,EAAE,WAAW,CAAC;QAChD,OAAO,EAAE,CAAC;KACX;IACD,KAAK,EAAE;QACL,IAAI,EAAE,CAAC,yBAAyB,CAAC;QACjC,OAAO,EAAE,GAAG;KACb;CACF,CAAC;AAEF,8CAA8C;AAC9C,MAAM,CAAC,MAAM,mBAAmB,GAAG;IACjC,kBAAkB,EAAE,KAAK;IACzB,sBAAsB,EAAE,KAA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C,CAAC;QACjF,KAAK,MAAM,SAAS,IAAI,UAAU,EAAE,CAAC;YACnC,YAAY,CAAC,IAAI,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC,IAAI,CAAC,CAAC;QAC9C,CAAC;IACH,CAAC;IACD,IAAI,aAAa,GAAG,CAAC,CAAC;IACtB,IAAI,CAAC,CAAA,YAAY,aAAZ,YAAY,uBAAZ,YAAY,CAAE,MAAM,CAAA,EAAE,CAAC;QAC1B,OAAO,WAAW,aAAa,EAAE,CAAC;IACpC,CAAC;IACD,SAAS,CAAC,oCAAoC,CAAC,YAAY,CAAC,CAAC;IAE7D,MAAM,eAAe,GAAG,IAAI,GAAG,CAAC,YAAY,CAAC,CAAC;IAC9C,OAAO,IAAI,EAAE,CAAC;QACZ,MAAM,WAAW,GAAG,WAAW,aAAa,EAAE,CAAC;QAC/C,IAAI,CAAC,eAAe,CAAC,GAAG,CAAC,WAAW,CAAC,EAAE,CAAC;YACtC,OAAO,WAAW,CAAC;QACrB,CAAC;QACD,aAAa,EAAE,CAAC;IAClB,CAAC;AACH,CAAC,CAAA,CAAC;AAEF,MAAM,gBAAgB,GAAG;IACvB,sBAAsB;IACtB,oBAAoB;CACrB,CAAC;AAEF,eAAe,gBAAgB,CAAC","sourcesContent":["import PkcJs from \"../../lib/pkc-js\";\nimport validator from \"../../lib/validator\";\nimport chain from \"../../lib/chain\";\nimport { v4 as uuid } from \"uuid\";\nimport accountsDatabase from \"./accounts-database\";\nimport { Accounts, AccountCommunity, ChainProviders } from \"../../types\";\nimport {\n getPkcClientOptions,\n normalizeAccountProtocolConfig,\n withProtocolAliases,\n} from \"../../lib/pkc-compat\";\nimport Logger from \"@pkcprotocol/pkc-logger\";\nconst log = Logger(\"bitsocial-react-hooks:accounts:stores\");\n\nexport const DEFAULT_ETH_RPC_URL = \"https://ethereum-rpc.publicnode.com\";\n\n// default chain providers\nconst chainProviders: ChainProviders = {\n eth: {\n // default should not use a url, but rather ethers' default provider\n urls: [DEFAULT_ETH_RPC_URL, \"viem\", \"ethers.js\"],\n chainId: 1,\n },\n matic: {\n urls: [\"https://polygon-rpc.com\"],\n chainId: 137,\n },\n};\n\n// force using these options or can cause bugs\nexport const overwritePkcOptions = {\n resolveAuthorNames: false,\n resolveAuthorAddresses: false,\n validatePages: false,\n};\n\nconst aliasProtocolOptions = (options: Record<string, any>) => ({\n ...options,\n resolveAuthorNames: options.resolveAuthorNames ?? options.resolveAuthorAddresses ?? false,\n resolveAuthorAddresses: options.resolveAuthorAddresses ?? options.resolveAuthorNames ?? false,\n});\n\nconst addMissingChainProviders = (options: Record<string, any>) => {\n const optionsWithChainProviders = { ...options };\n if (!optionsWithChainProviders.chainProviders) {\n optionsWithChainProviders.chainProviders = {};\n }\n for (const chainTicker in chainProviders) {\n if (!optionsWithChainProviders.chainProviders[chainTicker]) {\n optionsWithChainProviders.chainProviders[chainTicker] = chainProviders[chainTicker];\n }\n }\n return optionsWithChainProviders;\n};\n\nexport const getDefaultChainProviders = () => {\n // @ts-ignore\n const defaultWindowOptions = window.defaultPkcOptions;\n const windowChainProviders = defaultWindowOptions?.chainProviders\n ? JSON.parse(JSON.stringify(defaultWindowOptions.chainProviders))\n : undefined;\n return addMissingChainProviders({\n chainProviders: windowChainProviders,\n }).chainProviders as ChainProviders;\n};\n\n// default options aren't saved to database so they can be changed\nexport const getDefaultPkcOptions = () => {\n // default PKC options defined by the electron process\n // @ts-ignore\n const defaultWindowOptions = window.defaultPkcOptions;\n if (defaultWindowOptions) {\n // @ts-ignore\n const defaultPkcOptions: any = JSON.parse(\n JSON.stringify({ ...defaultWindowOptions, libp2pJsClientsOptions: undefined }),\n );\n delete defaultPkcOptions.chainProviders;\n delete defaultPkcOptions.nameResolversChainProviders;\n // @ts-ignore\n defaultPkcOptions.libp2pJsClientsOptions = defaultWindowOptions.libp2pJsClientsOptions; // libp2pJsClientsOptions is not always just json\n return aliasProtocolOptions({ ...defaultPkcOptions, ...overwritePkcOptions });\n }\n // default PKC options for web client\n return aliasProtocolOptions({\n ipfsGatewayUrls: [\n \"https://ipfsgateway.xyz\",\n \"https://gateway.plebpubsub.xyz\",\n \"https://gateway.forumindex.com\",\n ],\n kuboRpcClientsOptions: undefined,\n pubsubKuboRpcClientsOptions: [\n \"https://pubsubprovider.xyz/api/v0\",\n \"https://plebpubsub.xyz/api/v0\",\n \"https://rannithepleb.com/api/v0\",\n ],\n httpRoutersOptions: [\n \"https://routing.lol\",\n \"https://peers.pleb.bot\",\n \"https://peers.plebpubsub.xyz\",\n \"https://peers.forumindex.com\",\n ],\n ...overwritePkcOptions,\n });\n};\n\n// the gateway to use in <img src> for nft avatars\n// @ts-ignore\nconst defaultMediaIpfsGatewayUrl = window.defaultMediaIpfsGatewayUrl || \"https://ipfs.io\";\n\nconst generateDefaultAccount = async () => {\n const pkcOptions = getDefaultPkcOptions();\n const chainProviders = getDefaultChainProviders();\n const pkc = await PkcJs.PKC(\n getPkcClientOptions(\n {\n chainProviders,\n pkcOptions,\n },\n pkcOptions,\n ),\n );\n // handle errors or error events are uncaught\n // no need to log them because pkc-js already logs them\n pkc.on(\"error\", (error: any) =>\n log.error(\"uncaught pkc instance error, should never happen\", { error }),\n );\n\n const signer = await pkc.createSigner();\n const author = {\n address: signer.address,\n wallets: {\n eth: await chain.getEthWalletFromPkcPrivateKey(signer.privateKey, signer.address),\n },\n };\n\n const accountName = await getNextAvailableDefaultAccountName();\n\n // communities where the account has a role, like moderator, admin, owner, etc.\n const communities: { [communityAddress: string]: AccountCommunity } = {};\n\n const account = normalizeAccountProtocolConfig(\n withProtocolAliases(\n {\n id: uuid(),\n version: accountsDatabase.accountVersion,\n name: accountName,\n author,\n signer,\n chainProviders,\n pkcOptions,\n subscriptions: [],\n blockedAddresses: {},\n blockedCids: {},\n communities,\n mediaIpfsGatewayUrl: defaultMediaIpfsGatewayUrl,\n },\n pkc,\n pkcOptions,\n ),\n chainProviders,\n );\n return account;\n};\n\nconst getNextAvailableDefaultAccountName = async () => {\n const accountIds: string[] | null =\n await accountsDatabase.accountsMetadataDatabase.getItem(\"accountIds\");\n const accountNames = [];\n if (accountIds?.length) {\n const accounts: Accounts | null = await accountsDatabase.getAccounts(accountIds);\n for (const accountId of accountIds) {\n accountNames.push(accounts[accountId].name);\n }\n }\n let accountNumber = 1;\n if (!accountNames?.length) {\n return `Account ${accountNumber}`;\n }\n validator.validateAccountsDatabaseAccountNames(accountNames);\n\n const accountNamesSet = new Set(accountNames);\n while (true) {\n const accountName = `Account ${accountNumber}`;\n if (!accountNamesSet.has(accountName)) {\n return accountName;\n }\n accountNumber++;\n }\n};\n\nconst accountGenerator = {\n generateDefaultAccount,\n getDefaultPkcOptions,\n};\n\nexport default accountGenerator;\n"]}
|
|
1
|
+
{"version":3,"file":"account-generator.js","sourceRoot":"","sources":["../../../src/stores/accounts/account-generator.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,KAAK,MAAM,kBAAkB,CAAC;AACrC,OAAO,SAAS,MAAM,qBAAqB,CAAC;AAC5C,OAAO,KAAK,MAAM,iBAAiB,CAAC;AACpC,OAAO,EAAE,EAAE,IAAI,IAAI,EAAE,MAAM,MAAM,CAAC;AAClC,OAAO,gBAAgB,MAAM,qBAAqB,CAAC;AAEnD,OAAO,EACL,mBAAmB,EACnB,8BAA8B,EAC9B,mBAAmB,GACpB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,MAAM,MAAM,yBAAyB,CAAC;AAC7C,MAAM,GAAG,GAAG,MAAM,CAAC,uCAAuC,CAAC,CAAC;AAE5D,MAAM,CAAC,MAAM,mBAAmB,GAAG,qCAAqC,CAAC;AACzE,MAAM,CAAC,MAAM,oBAAoB,GAAG;IAClC,mBAAmB;IACnB,sBAAsB;IACtB,iCAAiC;IACjC,2BAA2B;IAC3B,qBAAqB;IACrB,6BAA6B;CAC9B,CAAC;AAEF,0BAA0B;AAC1B,MAAM,cAAc,GAAmB;IACrC,GAAG,EAAE;QACH,qFAAqF;QACrF,IAAI,EAAE,CAAC,GAAG,oBAAoB,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AAU,GACd,MAAM,gBAAgB,CAAC,wBAAwB,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC;IACxE,MAAM,YAAY,GAAG,EAAE,CAAC;IACxB,IAAI,UAAU,aAAV,UAAU,uBAAV,UAAU,CAAE,MAAM,EAAE,CAAC;QACvB,MAAM,QAAQ,GAAoB,MAAM,gBAAgB,CAAC,WAAW,CAAC,UAAU,CAAC,CAAC;QACjF,KAAK,MAAM,SAAS,IAAI,UAAU,EAAE,CAAC;YACnC,YAAY,CAAC,IAAI,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC,IAAI,CAAC,CAAC;QAC9C,CAAC;IACH,CAAC;IACD,IAAI,aAAa,GAAG,CAAC,CAAC;IACtB,IAAI,CAAC,CAAA,YAAY,aAAZ,YAAY,uBAAZ,YAAY,CAAE,MAAM,CAAA,EAAE,CAAC;QAC1B,OAAO,WAAW,aAAa,EAAE,CAAC;IACpC,CAAC;IACD,SAAS,CAAC,oCAAoC,CAAC,YAAY,CAAC,CAAC;IAE7D,MAAM,eAAe,GAAG,IAAI,GAAG,CAAC,YAAY,CAAC,CAAC;IAC9C,OAAO,IAAI,EAAE,CAAC;QACZ,MAAM,WAAW,GAAG,WAAW,aAAa,EAAE,CAAC;QAC/C,IAAI,CAAC,eAAe,CAAC,GAAG,CAAC,WAAW,CAAC,EAAE,CAAC;YACtC,OAAO,WAAW,CAAC;QACrB,CAAC;QACD,aAAa,EAAE,CAAC;IAClB,CAAC;AACH,CAAC,CAAA,CAAC;AAEF,MAAM,gBAAgB,GAAG;IACvB,sBAAsB;IACtB,oBAAoB;CACrB,CAAC;AAEF,eAAe,gBAAgB,CAAC","sourcesContent":["import PkcJs from \"../../lib/pkc-js\";\nimport validator from \"../../lib/validator\";\nimport chain from \"../../lib/chain\";\nimport { v4 as uuid } from \"uuid\";\nimport accountsDatabase from \"./accounts-database\";\nimport { Accounts, AccountCommunity, ChainProviders } from \"../../types\";\nimport {\n getPkcClientOptions,\n normalizeAccountProtocolConfig,\n withProtocolAliases,\n} from \"../../lib/pkc-compat\";\nimport Logger from \"@pkcprotocol/pkc-logger\";\nconst log = Logger(\"bitsocial-react-hooks:accounts:stores\");\n\nexport const DEFAULT_ETH_RPC_URL = \"https://ethereum-rpc.publicnode.com\";\nexport const DEFAULT_ETH_RPC_URLS = [\n DEFAULT_ETH_RPC_URL,\n \"https://eth.drpc.org\",\n \"https://ethereum.publicnode.com\",\n \"https://rpc.mevblocker.io\",\n \"https://1rpc.io/eth\",\n \"https://eth-pokt.nodies.app\",\n];\n\n// default chain providers\nconst chainProviders: ChainProviders = {\n eth: {\n // Use explicit RPCs for default name resolution; viem's default transport is opt-in.\n urls: [...DEFAULT_ETH_RPC_URLS, \"ethers.js\"],\n chainId: 1,\n },\n matic: {\n urls: [\"https://polygon-rpc.com\"],\n chainId: 137,\n },\n};\n\n// force using these options or can cause bugs\nexport const overwritePkcOptions = {\n resolveAuthorNames: false,\n resolveAuthorAddresses: false,\n validatePages: false,\n};\n\nconst aliasProtocolOptions = (options: Record<string, any>) => ({\n ...options,\n resolveAuthorNames: options.resolveAuthorNames ?? options.resolveAuthorAddresses ?? false,\n resolveAuthorAddresses: options.resolveAuthorAddresses ?? options.resolveAuthorNames ?? false,\n});\n\nconst addMissingChainProviders = (options: Record<string, any>) => {\n const optionsWithChainProviders = { ...options };\n if (!optionsWithChainProviders.chainProviders) {\n optionsWithChainProviders.chainProviders = {};\n }\n for (const chainTicker in chainProviders) {\n if (!optionsWithChainProviders.chainProviders[chainTicker]) {\n optionsWithChainProviders.chainProviders[chainTicker] = chainProviders[chainTicker];\n }\n }\n return optionsWithChainProviders;\n};\n\nexport const getDefaultChainProviders = () => {\n // @ts-ignore\n const defaultWindowOptions = window.defaultPkcOptions;\n const windowChainProviders = defaultWindowOptions?.chainProviders\n ? JSON.parse(JSON.stringify(defaultWindowOptions.chainProviders))\n : undefined;\n return addMissingChainProviders({\n chainProviders: windowChainProviders,\n }).chainProviders as ChainProviders;\n};\n\n// default options aren't saved to database so they can be changed\nexport const getDefaultPkcOptions = () => {\n // default PKC options defined by the electron process\n // @ts-ignore\n const defaultWindowOptions = window.defaultPkcOptions;\n if (defaultWindowOptions) {\n // @ts-ignore\n const defaultPkcOptions: any = JSON.parse(\n JSON.stringify({ ...defaultWindowOptions, libp2pJsClientsOptions: undefined }),\n );\n delete defaultPkcOptions.chainProviders;\n delete defaultPkcOptions.nameResolversChainProviders;\n // @ts-ignore\n defaultPkcOptions.libp2pJsClientsOptions = defaultWindowOptions.libp2pJsClientsOptions; // libp2pJsClientsOptions is not always just json\n return aliasProtocolOptions({ ...defaultPkcOptions, ...overwritePkcOptions });\n }\n // default PKC options for web client\n return aliasProtocolOptions({\n ipfsGatewayUrls: [\n \"https://ipfsgateway.xyz\",\n \"https://gateway.plebpubsub.xyz\",\n \"https://gateway.forumindex.com\",\n ],\n kuboRpcClientsOptions: undefined,\n pubsubKuboRpcClientsOptions: [\n \"https://pubsubprovider.xyz/api/v0\",\n \"https://plebpubsub.xyz/api/v0\",\n \"https://rannithepleb.com/api/v0\",\n ],\n httpRoutersOptions: [\n \"https://routing.lol\",\n \"https://peers.pleb.bot\",\n \"https://peers.plebpubsub.xyz\",\n \"https://peers.forumindex.com\",\n ],\n ...overwritePkcOptions,\n });\n};\n\n// the gateway to use in <img src> for nft avatars\n// @ts-ignore\nconst defaultMediaIpfsGatewayUrl = window.defaultMediaIpfsGatewayUrl || \"https://ipfs.io\";\n\nconst generateDefaultAccount = async () => {\n const pkcOptions = getDefaultPkcOptions();\n const chainProviders = getDefaultChainProviders();\n const pkc = await PkcJs.PKC(\n getPkcClientOptions(\n {\n chainProviders,\n pkcOptions,\n },\n pkcOptions,\n ),\n );\n // handle errors or error events are uncaught\n // no need to log them because pkc-js already logs them\n pkc.on(\"error\", (error: any) =>\n log.error(\"uncaught pkc instance error, should never happen\", { error }),\n );\n\n const signer = await pkc.createSigner();\n const author = {\n address: signer.address,\n wallets: {\n eth: await chain.getEthWalletFromPkcPrivateKey(signer.privateKey, signer.address),\n },\n };\n\n const accountName = await getNextAvailableDefaultAccountName();\n\n // communities where the account has a role, like moderator, admin, owner, etc.\n const communities: { [communityAddress: string]: AccountCommunity } = {};\n\n const account = normalizeAccountProtocolConfig(\n withProtocolAliases(\n {\n id: uuid(),\n version: accountsDatabase.accountVersion,\n name: accountName,\n author,\n signer,\n chainProviders,\n pkcOptions,\n subscriptions: [],\n blockedAddresses: {},\n blockedCids: {},\n communities,\n mediaIpfsGatewayUrl: defaultMediaIpfsGatewayUrl,\n },\n pkc,\n pkcOptions,\n ),\n chainProviders,\n );\n return account;\n};\n\nconst getNextAvailableDefaultAccountName = async () => {\n const accountIds: string[] | null =\n await accountsDatabase.accountsMetadataDatabase.getItem(\"accountIds\");\n const accountNames = [];\n if (accountIds?.length) {\n const accounts: Accounts | null = await accountsDatabase.getAccounts(accountIds);\n for (const accountId of accountIds) {\n accountNames.push(accounts[accountId].name);\n }\n }\n let accountNumber = 1;\n if (!accountNames?.length) {\n return `Account ${accountNumber}`;\n }\n validator.validateAccountsDatabaseAccountNames(accountNames);\n\n const accountNamesSet = new Set(accountNames);\n while (true) {\n const accountName = `Account ${accountNumber}`;\n if (!accountNamesSet.has(accountName)) {\n return accountName;\n }\n accountNumber++;\n }\n};\n\nconst accountGenerator = {\n generateDefaultAccount,\n getDefaultPkcOptions,\n};\n\nexport default accountGenerator;\n"]}
|
package/package.json
CHANGED
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
"publishConfig": {
|
|
14
14
|
"access": "public"
|
|
15
15
|
},
|
|
16
|
-
"version": "0.1.
|
|
16
|
+
"version": "0.1.3",
|
|
17
17
|
"packageManager": "yarn@4.13.0",
|
|
18
18
|
"files": [
|
|
19
19
|
"dist"
|
|
@@ -45,7 +45,7 @@
|
|
|
45
45
|
},
|
|
46
46
|
"dependencies": {
|
|
47
47
|
"@bitsocial/bso-resolver": "0.0.6",
|
|
48
|
-
"@pkcprotocol/pkc-js": "0.0.
|
|
48
|
+
"@pkcprotocol/pkc-js": "0.0.23",
|
|
49
49
|
"@pkcprotocol/pkc-logger": "0.1.0",
|
|
50
50
|
"assert": "2.0.0",
|
|
51
51
|
"ethers": "5.8.0",
|