diff --git a/.gitignore b/.gitignore
index 0c426e1a..1af11c4b 100644
--- a/.gitignore
+++ b/.gitignore
@@ -62,4 +62,6 @@ cache/
.yarn/install-state.gz
-storybook-static
\ No newline at end of file
+storybook-static
+
+.million
\ No newline at end of file
diff --git a/apps/console/next.config.js b/apps/console/next.config.js
index cffac9d0..a4720cf2 100644
--- a/apps/console/next.config.js
+++ b/apps/console/next.config.js
@@ -2,6 +2,7 @@
// eslint-disable-next-line @typescript-eslint/no-var-requires
const { composePlugins, withNx } = require('@nx/next');
+const MillionLint = require('@million/lint');
/**
* @type {import('@nx/next/plugins/with-nx').WithNxOptions}
@@ -13,6 +14,9 @@ const nextConfig = {
// See: https://github.com/gregberge/svgr
svgr: false,
},
+ experimental: {
+ serverComponentsExternalPackages: ['@xmtp/user-preferences-bindings-wasm'],
+ },
};
const plugins = [
@@ -20,4 +24,6 @@ const plugins = [
withNx,
];
-module.exports = composePlugins(...plugins)(nextConfig);
+module.exports = MillionLint.next({ rsc: true })(
+ composePlugins(...plugins)(nextConfig)
+);
diff --git a/apps/console/src/app/page.tsx b/apps/console/src/app/page.tsx
index 197422c9..3de9aa76 100644
--- a/apps/console/src/app/page.tsx
+++ b/apps/console/src/app/page.tsx
@@ -40,6 +40,7 @@ export default function Page() {
+
diff --git a/apps/console/src/app/providers.tsx b/apps/console/src/app/providers.tsx
index f709020d..b4b11657 100644
--- a/apps/console/src/app/providers.tsx
+++ b/apps/console/src/app/providers.tsx
@@ -63,6 +63,7 @@ export const Providers: React.FC = (props) => {
providerUrl: process.env.NEXT_PUBLIC_SEPOLIA_PROVIDER_URL as string,
},
],
+ enableAuth: true,
openOnWalletConnect: true,
allowedEns: 'all',
disableOverlay: true,
diff --git a/apps/console/src/components/sections/code/CodeSection/index.tsx b/apps/console/src/components/sections/code/CodeSection/index.tsx
index c4da154f..31b2bc7d 100644
--- a/apps/console/src/components/sections/code/CodeSection/index.tsx
+++ b/apps/console/src/components/sections/code/CodeSection/index.tsx
@@ -32,6 +32,11 @@ export const CodeSection: React.FC = ({ mobile }) => {
[config]
);
+ const xmtpPluginEnabled = useMemo(
+ () => config.plugins?.find((p) => p.name === 'XMTPPlugin'),
+ [config]
+ );
+
const codeSnippet = useMemo(() => {
const plugins = [];
@@ -57,6 +62,10 @@ export const CodeSection: React.FC = ({ mobile }) => {
);
}
+ if (xmtpPluginEnabled) {
+ plugins.push("%%XMTPPlugin('production')%%");
+ }
+
return `
import '@rainbow-me/rainbowkit/styles.css';
import '@justweb3/widget/styles.css';
@@ -97,6 +106,9 @@ ${
? "import { TalentProtocolPlugin } from '@justweb3/talent-protocol-plugin';"
: ''
}
+${
+ xmtpPluginEnabled ? "import { XMTPPlugin } from '@justweb3/xmtp-plugin';" : ''
+}
export const App: React.FC = () => {
const { wallets } = getDefaultWallets();
@@ -163,6 +175,7 @@ export default App;`.trim();
justVerifiedEnabled,
poapPluginEnabled,
talentProtocolPluginEnabled,
+ xmtpPluginEnabled,
]);
const code = useMemo(() => {
@@ -172,9 +185,11 @@ export default App;`.trim();
}, [codeSnippet]);
const dependencies = useMemo(() => {
- return `yarn add ${justVerifiedEnabled ? '@justverified/plugin' : ''} ${
- poapPluginEnabled ? '@justweb3/poap-plugin' : ''
- } ${efpPluginEnabled ? '@justweb3/efp-plugin' : ''}
+ return `yarn add ${xmtpPluginEnabled ? '@justweb3/xmtp-plugin' : ''} ${
+ justVerifiedEnabled ? '@justverified/plugin' : ''
+ } ${poapPluginEnabled ? '@justweb3/poap-plugin' : ''} ${
+ efpPluginEnabled ? '@justweb3/efp-plugin' : ''
+ }
${talentProtocolPluginEnabled ? '@justweb3/talent-protocol-plugin' : ''}
@justweb3/widget viem wagmi @rainbow-me/rainbowkit @tanstack/react-query ethers`;
}, [
@@ -182,6 +197,7 @@ export default App;`.trim();
justVerifiedEnabled,
poapPluginEnabled,
talentProtocolPluginEnabled,
+ xmtpPluginEnabled,
]);
const handleDependenciesCopy = () => {
diff --git a/apps/console/src/components/sections/customizer/PluginsSection/Verified/index.tsx b/apps/console/src/components/sections/customizer/PluginsSection/JustVerified/index.tsx
similarity index 99%
rename from apps/console/src/components/sections/customizer/PluginsSection/Verified/index.tsx
rename to apps/console/src/components/sections/customizer/PluginsSection/JustVerified/index.tsx
index 1c6ca75e..882d8b18 100644
--- a/apps/console/src/components/sections/customizer/PluginsSection/Verified/index.tsx
+++ b/apps/console/src/components/sections/customizer/PluginsSection/JustVerified/index.tsx
@@ -45,7 +45,7 @@ const socials: { logo: ReactNode; title: string; credential: Credentials }[] = [
},
];
-export const Verified = () => {
+export const JustVerified = () => {
const { handleJustWeb3Config, config } = useContext(JustWeb3Context);
const { justVerified, setJustVerified } = useConsole();
diff --git a/apps/console/src/components/sections/customizer/PluginsSection/Verified/socialCard/index.tsx b/apps/console/src/components/sections/customizer/PluginsSection/JustVerified/socialCard/index.tsx
similarity index 100%
rename from apps/console/src/components/sections/customizer/PluginsSection/Verified/socialCard/index.tsx
rename to apps/console/src/components/sections/customizer/PluginsSection/JustVerified/socialCard/index.tsx
diff --git a/apps/console/src/components/sections/customizer/PluginsSection/XMTP/index.tsx b/apps/console/src/components/sections/customizer/PluginsSection/XMTP/index.tsx
new file mode 100644
index 00000000..aa17765f
--- /dev/null
+++ b/apps/console/src/components/sections/customizer/PluginsSection/XMTP/index.tsx
@@ -0,0 +1,49 @@
+// import { AccordionItem, AccordionTrigger } from '../../../../ui/accordion';
+import { Switch } from '../../../../ui/switch';
+import { useContext } from 'react';
+import { JustWeb3Context } from '@justweb3/widget';
+import { XMTPPlugin } from '@justweb3/xmtp-plugin';
+
+export const XMTP = () => {
+ const { handleJustWeb3Config, config } = useContext(JustWeb3Context);
+
+ const handleEFPConfig = (enabled: boolean) => {
+ if (enabled) {
+ handleJustWeb3Config({
+ ...config,
+ plugins: [
+ ...(config?.plugins || []).filter(
+ (plugin) => plugin.name !== XMTPPlugin.name
+ ),
+ XMTPPlugin('production'),
+ ],
+ });
+ } else {
+ handleJustWeb3Config({
+ ...config,
+ plugins: (config?.plugins || []).filter(
+ (plugin) => plugin.name !== XMTPPlugin.name
+ ),
+ });
+ }
+ };
+
+ return (
+
+
+ XMTP
+
+
plugin.name === XMTPPlugin.name)
+ }
+ onClick={(e) => {
+ e.stopPropagation();
+ }}
+ onCheckedChange={(checked) => {
+ handleEFPConfig(checked);
+ }}
+ />
+
+ );
+};
diff --git a/apps/console/src/components/sections/customizer/PluginsSection/index.tsx b/apps/console/src/components/sections/customizer/PluginsSection/index.tsx
index 5d4e59bd..06321f97 100644
--- a/apps/console/src/components/sections/customizer/PluginsSection/index.tsx
+++ b/apps/console/src/components/sections/customizer/PluginsSection/index.tsx
@@ -1,9 +1,10 @@
import { FC } from 'react';
import { Accordion } from '../../../ui/accordion';
-import { Verified } from './Verified';
+import { JustVerified } from './JustVerified';
import { EFP } from './EFP';
import { POAP } from './POAP';
import { TalentProtocol } from './TalentProtocol';
+import { XMTP } from './XMTP';
export const PluginsSection: FC = () => {
return (
@@ -13,12 +14,14 @@ export const PluginsSection: FC = () => {
+
{/* */}
diff --git a/demo/server/src/main.ts b/demo/server/src/main.ts
index b3d71883..06f75887 100644
--- a/demo/server/src/main.ts
+++ b/demo/server/src/main.ts
@@ -68,9 +68,15 @@ app.post('/api/signin', async (req: Request, res) => {
return;
}
+ if (!req.session.nonce) {
+ res.status(401).json({ message: 'No nonce found.' });
+ return;
+ }
+
const { data: message, ens } = await justaname.signIn.signIn({
message: req.body.message,
signature: req.body.signature,
+ nonce: req.session.nonce,
});
if (!message) {
diff --git a/package.json b/package.json
index d3e05ddc..e3ed50e1 100644
--- a/package.json
+++ b/package.json
@@ -18,6 +18,8 @@
"@hookform/error-message": "^2.0.1",
"@hookform/resolvers": "^3.9.0",
"@inquirer/prompts": "^4.3.0",
+ "@justaname.id/address-resolution": "^1.1.0",
+ "@million/lint": "^1.0.13",
"@privy-io/react-auth": "^1.82.0",
"@privy-io/wagmi": "^0.2.12",
"@radix-ui/react-accordion": "^1.2.1",
@@ -99,6 +101,7 @@
"react-native-url-polyfill": "^2.0.0",
"react-native-web": "~0.19.9",
"react-router-dom": "6.11.2",
+ "react-scan": "^0.0.35",
"react-split": "^2.0.14",
"react-timer-hook": "^3.0.8",
"react-tiny-popover": "^8.0.4",
diff --git a/packages/@justaname.id/react/CHANGELOG.md b/packages/@justaname.id/react/CHANGELOG.md
index 5944fd22..18b3f63d 100644
--- a/packages/@justaname.id/react/CHANGELOG.md
+++ b/packages/@justaname.id/react/CHANGELOG.md
@@ -1,3 +1,122 @@
+## 0.3.158 (2024-12-03)
+
+
+### 🚀 Features
+
+- sign in optional ([3df90a7](https://github.com/JustaName-id/JustaName-sdk/commit/3df90a7))
+
+
+### 🧱 Updated Dependencies
+
+- Updated @justaname.id/sdk to 0.2.155
+
+
+### ❤️ Thank You
+
+- HadiKhai
+
+## 0.3.157 (2024-12-02)
+
+
+### 🧱 Updated Dependencies
+
+- Updated @justaname.id/sdk to 0.2.154
+
+## 0.3.156 (2024-12-01)
+
+
+### 🚀 Features
+
+- support ethers 5 and ethers 6 ([f82ab13](https://github.com/JustaName-id/JustaName-sdk/commit/f82ab13))
+
+
+### 🧱 Updated Dependencies
+
+- Updated @justaname.id/sdk to 0.2.153
+
+
+### ❤️ Thank You
+
+- HadiKhai
+
+## 0.3.155 (2024-11-29)
+
+
+### 🧱 Updated Dependencies
+
+- Updated @justaname.id/sdk to 0.2.152
+
+## 0.3.154 (2024-11-29)
+
+
+### 🧱 Updated Dependencies
+
+- Updated @justaname.id/sdk to 0.2.151
+
+## 0.3.153 (2024-11-29)
+
+
+### 🧱 Updated Dependencies
+
+- Updated @justaname.id/sdk to 0.2.150
+
+## 0.3.152 (2024-11-29)
+
+
+### 🧱 Updated Dependencies
+
+- Updated @justaname.id/sdk to 0.2.149
+
+## 0.3.151 (2024-11-29)
+
+
+### 🧱 Updated Dependencies
+
+- Updated @justaname.id/sdk to 0.2.148
+
+## 0.3.150 (2024-11-29)
+
+
+### 🚀 Features
+
+- remove mapps from justverified ([2898c521](https://github.com/JustaName-id/JustaName-sdk/commit/2898c521))
+
+- efp ([36fcc153](https://github.com/JustaName-id/JustaName-sdk/commit/36fcc153))
+
+- efp and storybook for react sdk ([f0c5c7a0](https://github.com/JustaName-id/JustaName-sdk/commit/f0c5c7a0))
+
+- console fixes ([358b3a0e](https://github.com/JustaName-id/JustaName-sdk/commit/358b3a0e))
+
+- added docs and the sign in should only show ens set to default resolver or justaname resolver only ([a3bcecaa](https://github.com/JustaName-id/JustaName-sdk/commit/a3bcecaa))
+
+- enabled in hooks and siwens fix and coinbase fix ([c3fb455e](https://github.com/JustaName-id/JustaName-sdk/commit/c3fb455e))
+
+- retryOnMount false ([bec00ba8](https://github.com/JustaName-id/JustaName-sdk/commit/bec00ba8))
+
+
+### 🩹 Fixes
+
+- packages ([6dd450f5](https://github.com/JustaName-id/JustaName-sdk/commit/6dd450f5))
+
+- lint fix on react and package json of projects ([b29cd296](https://github.com/JustaName-id/JustaName-sdk/commit/b29cd296))
+
+- error from useEnsWalletClient ([67043376](https://github.com/JustaName-id/JustaName-sdk/commit/67043376))
+
+- update rest call and ui fixes ([81b05f29](https://github.com/JustaName-id/JustaName-sdk/commit/81b05f29))
+
+- poap default options ([eb5d1c36](https://github.com/JustaName-id/JustaName-sdk/commit/eb5d1c36))
+
+
+### 🧱 Updated Dependencies
+
+- Updated @justaname.id/sdk to 0.2.147
+
+
+### ❤️ Thank You
+
+- anthony2399 @anthony23991
+- HadiKhai
+
## 0.3.149 (2024-11-15)
diff --git a/packages/@justaname.id/react/package.json b/packages/@justaname.id/react/package.json
index c7e321d5..e3f639be 100644
--- a/packages/@justaname.id/react/package.json
+++ b/packages/@justaname.id/react/package.json
@@ -1,15 +1,15 @@
{
"name": "@justaname.id/react",
- "version": "0.3.149",
+ "version": "0.3.158",
"dependencies": {
"@ensdomains/ensjs": "4.0.2",
- "@justaname.id/sdk": "0.2.146",
+ "@justaname.id/sdk": "0.2.155",
"axios": "^1.6.0",
"qs": "^6.12.0"
},
"peerDependencies": {
"@tanstack/react-query": "^5.x",
- "ethers": "^6.x",
+ "ethers": "^5.6.8 || ^6.0.8",
"react": ">=17",
"viem": "2.x",
"wagmi": "2.x"
diff --git a/packages/@justaname.id/react/src/lib/helpers/ethersCompat.ts b/packages/@justaname.id/react/src/lib/helpers/ethersCompat.ts
new file mode 100644
index 00000000..682e9f25
--- /dev/null
+++ b/packages/@justaname.id/react/src/lib/helpers/ethersCompat.ts
@@ -0,0 +1,51 @@
+// inspired by spruceid siwe: https://github.com/spruceid/siwe/blob/main/packages/siwe/lib/ethersCompat.ts
+
+import { ethers } from 'ethers';
+
+// @ts-expect-error -- compatibility hack
+type ProviderV5 = ethers.providers.Provider;
+type ProviderV6 = ethers.Provider;
+// @ts-expect-error -- compatibility hack
+type JsonRpcProviderV5 = ethers.providers.JsonRpcProvider;
+type JsonRpcProviderV6 = ethers.JsonRpcProvider;
+
+export type Provider = ProviderV6 extends undefined ? ProviderV5 : ProviderV6;
+export type JsonRpcProvider = JsonRpcProviderV6 extends undefined
+ ? JsonRpcProviderV5
+ : JsonRpcProviderV6;
+
+interface EthersCompat {
+ namehash?: (name: string) => string;
+ getAddress?: (address: string) => string;
+ JsonRpcProvider?: new (...args: any[]) => JsonRpcProvider;
+ utils: {
+ namehash: (name: string) => string;
+ getAddress: (address: string) => string;
+ };
+ providers: {
+ JsonRpcProvider: new (...args: any[]) => JsonRpcProvider;
+ };
+}
+
+const ethersCompat = ethers as unknown as EthersCompat;
+
+export const getJsonRpcProvider = (
+ providerUrl?: string,
+ chainId?: number
+): JsonRpcProvider => {
+ if ('JsonRpcProvider' in ethersCompat) {
+ return new ethersCompat.JsonRpcProvider!(providerUrl, chainId);
+ } else {
+ return new ethersCompat.providers.JsonRpcProvider(providerUrl, chainId);
+ }
+};
+
+export const namehash: (name: string) => string =
+ 'namehash' in ethersCompat
+ ? ethersCompat.namehash!
+ : ethersCompat.utils.namehash;
+
+export const getAddress: (address: string) => string =
+ 'getAddress' in ethersCompat
+ ? ethersCompat.getAddress!
+ : ethersCompat.utils.getAddress;
diff --git a/packages/@justaname.id/react/src/lib/helpers/isParseable/index.ts b/packages/@justaname.id/react/src/lib/helpers/isParseable/index.ts
new file mode 100644
index 00000000..a6d87b9a
--- /dev/null
+++ b/packages/@justaname.id/react/src/lib/helpers/isParseable/index.ts
@@ -0,0 +1,8 @@
+export const isParseable = (value: any): boolean => {
+ try {
+ JSON.parse(value);
+ return true;
+ } catch (e) {
+ return false;
+ }
+};
diff --git a/packages/@justaname.id/react/src/lib/helpers/validateEns.ts b/packages/@justaname.id/react/src/lib/helpers/validateEns.ts
new file mode 100644
index 00000000..684da86d
--- /dev/null
+++ b/packages/@justaname.id/react/src/lib/helpers/validateEns.ts
@@ -0,0 +1,25 @@
+import { normalize } from 'viem/ens';
+
+export const normalizeEns = (name: string | undefined): string | undefined => {
+ if (typeof name !== 'string' || name.trim() === '') {
+ return;
+ }
+
+ try {
+ const normalized = normalize(name);
+
+ return normalized;
+ } catch (error) {
+ return;
+ }
+};
+
+export const validateEns = (name: string | undefined): boolean => {
+ const ensRegex = /(?:^|[^a-zA-Z0-9-_.])(([^\s.]{1,63}\.)+[^\s.]{2,63})/;
+
+ if (typeof name !== 'string' || name.trim() === '') {
+ return false;
+ }
+
+ return ensRegex.test(name);
+};
diff --git a/packages/@justaname.id/react/src/lib/hooks/client/useEnsPublicClient.ts b/packages/@justaname.id/react/src/lib/hooks/client/useEnsPublicClient.ts
index 039c6fb5..288087d2 100644
--- a/packages/@justaname.id/react/src/lib/hooks/client/useEnsPublicClient.ts
+++ b/packages/@justaname.id/react/src/lib/hooks/client/useEnsPublicClient.ts
@@ -22,7 +22,7 @@ export const getEnsPublicClient = (
};
export const buildEnsPublicClientKey = (chainId: ChainId | undefined) => [
- 'CLIENT',
+ 'ENS_PUBLIC_CLIENT',
chainId,
];
diff --git a/packages/@justaname.id/react/src/lib/hooks/primaryName/usePrimaryName.ts b/packages/@justaname.id/react/src/lib/hooks/primaryName/usePrimaryName.ts
index aff748e2..2c704966 100644
--- a/packages/@justaname.id/react/src/lib/hooks/primaryName/usePrimaryName.ts
+++ b/packages/@justaname.id/react/src/lib/hooks/primaryName/usePrimaryName.ts
@@ -6,6 +6,7 @@ import { useEnsPublicClient } from '../client/useEnsPublicClient';
import { defaultOptions } from '../../query';
import { getName } from '@ensdomains/ensjs/public';
import { PrimaryNameTaskQueue } from './primary-name-task-queue';
+import { buildPrimaryNameBatchKey } from './usePrimaryNameBatch';
export const buildPrimaryName = (
address: string,
@@ -13,7 +14,7 @@ export const buildPrimaryName = (
) => ['PRIMARY_NAME', address, chainId];
export interface UsePrimaryNameParams {
- address?: Address;
+ address?: string;
chainId?: ChainId;
enabled?: boolean;
}
@@ -59,6 +60,16 @@ export const usePrimaryName = (
let name = '';
+ const primaryNames = queryClient.getQueryData(
+ buildPrimaryNameBatchKey(_chainId)
+ ) as Record;
+
+ if (primaryNames && _params?.address) {
+ if (primaryNames[_params?.address]) {
+ return primaryNames[_params.address];
+ }
+ }
+
const primaryNameGetByAddressResponse =
await justaname.subnames.getPrimaryNameByAddress({
address: params?.address,
@@ -72,7 +83,7 @@ export const usePrimaryName = (
throw new Error('Address is required');
}
return getName(ensClient, {
- address: params?.address,
+ address: params?.address as Address,
});
};
@@ -82,32 +93,12 @@ export const usePrimaryName = (
name = reverseResolution.name;
}
}
-
- // const reverseResolution = await getName(ensClient, {
- // address: params?.address,
- // });
- //
- // if (reverseResolution && reverseResolution?.name) {
- // name = reverseResolution.name;
- // } else {
- // const primaryNameGetByAddressResponse =
- // await justaname.subnames.getPrimaryNameByAddress({
- // address: params?.address,
- // chainId: _chainId,
- // });
- //
- // if (primaryNameGetByAddressResponse) {
- // name = primaryNameGetByAddressResponse.name;
- // }
- // }
- //
return name;
};
const query = useQuery({
...defaultOptions,
retry: (_count, error) => {
- console.log('Error fetching primary name', error, _count);
if (error?.message.includes('PrimaryNameNotFound')) {
return false;
}
@@ -116,7 +107,7 @@ export const usePrimaryName = (
queryKey: buildPrimaryName(params?.address || '', _chainId),
queryFn: () =>
getPrimaryName({
- address: params?.address,
+ address: params?.address as Address,
}),
enabled:
Boolean(params?.address) && Boolean(ensClient) && Boolean(_enabled),
diff --git a/packages/@justaname.id/react/src/lib/hooks/primaryName/usePrimaryNameBatch.ts b/packages/@justaname.id/react/src/lib/hooks/primaryName/usePrimaryNameBatch.ts
index ddd06a45..48ff1dce 100644
--- a/packages/@justaname.id/react/src/lib/hooks/primaryName/usePrimaryNameBatch.ts
+++ b/packages/@justaname.id/react/src/lib/hooks/primaryName/usePrimaryNameBatch.ts
@@ -17,10 +17,10 @@ export const buildPrimaryNameBatchKey = (chainId: ChainId | undefined) => [
chainId,
];
-export type PrimaryNameRecord = Record;
+export type PrimaryNameRecord = Record;
export interface UsePrimaryNameBatchParams {
- addresses?: Address[];
+ addresses?: string[];
chainId?: ChainId;
enabled?: boolean;
}
@@ -143,7 +143,7 @@ export const usePrimaryNameBatch = (
),
queryFn: () =>
getPrimaryNameBatch({
- addresses: params?.addresses,
+ addresses: params?.addresses as Address[],
}),
enabled:
Boolean(params?.addresses) && Boolean(ensClient) && Boolean(_enabled),
diff --git a/packages/@justaname.id/react/src/lib/hooks/records/useRecords.ts b/packages/@justaname.id/react/src/lib/hooks/records/useRecords.ts
index 58557c3b..51b421de 100644
--- a/packages/@justaname.id/react/src/lib/hooks/records/useRecords.ts
+++ b/packages/@justaname.id/react/src/lib/hooks/records/useRecords.ts
@@ -18,10 +18,11 @@ import { useMemo } from 'react';
import { Records } from '../../types';
import { defaultOptions } from '../../query';
import { RecordsTaskQueue } from './records-task-queue';
-import { checkEnsValid } from '../../helpers/checkEnsValid';
import { useEnsPublicClient } from '../client/useEnsPublicClient';
import { useOffchainResolvers } from '../offchainResolver';
import { getRecords as getEnsRecords } from '@ensdomains/ensjs/public';
+import { checkEnsValid } from '../../helpers/checkEnsValid';
+import { normalizeEns, validateEns } from '../../helpers/validateEns';
export const buildRecordsBySubnameKey = (
subname: string,
@@ -72,6 +73,7 @@ export const useRecords = (params?: UseRecordsParams): UseRecordsResult => {
() => params?.chainId || chainId,
[params?.chainId, chainId]
);
+ const _ens = useMemo(() => normalizeEns(params?.ens), [params?.ens]);
const { offchainResolvers } = useOffchainResolvers();
const { ensClient } = useEnsPublicClient({
chainId: _chainId,
@@ -86,8 +88,18 @@ export const useRecords = (params?: UseRecordsParams): UseRecordsResult => {
const getRecords = async (
_params: SubnameRecordsRoute['params']
): Promise => {
+ const __ens = normalizeEns(_params.ens);
+
+ if (!__ens) {
+ throw new Error('Invalid ENS name');
+ }
+
+ if (!validateEns(__ens)) {
+ throw new Error('Invalid ENS name');
+ }
+
const result = await justaname.subnames.getRecords({
- ens: _params.ens,
+ ens: __ens,
providerUrl: _params.providerUrl,
chainId: _params.chainId,
});
@@ -109,8 +121,18 @@ export const useRecords = (params?: UseRecordsParams): UseRecordsResult => {
throw new Error('Public client not found');
}
+ const __ens = normalizeEns(_params.ens) || _ens;
+
+ if (!__ens) {
+ throw new Error('Invalid ENS name');
+ }
+
+ if (!validateEns(__ens)) {
+ throw new Error('Invalid ENS name');
+ }
+
const result = await getEnsRecords(ensClient, {
- name: _params.ens,
+ name: __ens,
coins: Object.keys(coinTypeMap),
texts: [
...generalKeys,
@@ -126,7 +148,7 @@ export const useRecords = (params?: UseRecordsParams): UseRecordsResult => {
);
const record = {
- ens: _params.ens,
+ ens: __ens,
isJAN: result.resolverAddress === offchainResolver?.resolverAddress,
records: {
...result,
@@ -152,11 +174,19 @@ export const useRecords = (params?: UseRecordsParams): UseRecordsResult => {
forceUpdate = false
): Promise => {
const __chainId = _params?.chainId || _chainId;
+ const __ens = normalizeEns(_params?.ens) || _ens;
+ if (!__ens) {
+ throw new Error('Invalid ENS name');
+ }
+
+ if (!validateEns(__ens)) {
+ throw new Error('Invalid ENS name');
+ }
// const __standard = _params?.standard || params?.standard;
const __standard = false;
if (!forceUpdate) {
const cachedRecords = queryClient.getQueryData(
- buildRecordsBySubnameKey(_params?.ens, __chainId, __standard)
+ buildRecordsBySubnameKey(__ens, __chainId, __standard)
) as Records;
if (cachedRecords) {
return cachedRecords;
@@ -176,13 +206,16 @@ export const useRecords = (params?: UseRecordsParams): UseRecordsResult => {
let records: Records;
try {
records = await getRecords({
- ens: _params.ens,
+ ens: __ens,
chainId: __chainId,
providerUrl: __providerUrl,
});
} catch (error) {
+ if (error instanceof Error && error.message.includes('NotFound')) {
+ throw error;
+ }
records = await getStandardRecords({
- ens: _params.ens,
+ ens: __ens,
chainId: __chainId,
providerUrl: __providerUrl,
});
@@ -195,7 +228,7 @@ export const useRecords = (params?: UseRecordsParams): UseRecordsResult => {
// if (__standard) {
// records = await getStandardRecords({
- // ens: _params.ens,
+ // ens: __ens,
// chainId: __chainId,
// providerUrl: __providerUrl,
// });
@@ -208,7 +241,7 @@ export const useRecords = (params?: UseRecordsParams): UseRecordsResult => {
// }
queryClient.setQueryData(
- buildRecordsBySubnameKey(_params.ens, __chainId, __standard),
+ buildRecordsBySubnameKey(__ens, __chainId, __standard),
records
);
return records;
@@ -216,23 +249,31 @@ export const useRecords = (params?: UseRecordsParams): UseRecordsResult => {
const query = useQuery({
...defaultOptions,
- queryKey: buildRecordsBySubnameKey(
- params?.ens || '',
- _chainId
- // params?.standard
- ),
+ retry: (failureCount, error) => {
+ if (error instanceof Error) {
+ if (
+ error.message.includes('NotFound') ||
+ error.message.includes('ETH address not found')
+ ) {
+ return false;
+ }
+ }
+ return failureCount < 3;
+ },
+ queryKey: buildRecordsBySubnameKey(_ens || '', _chainId),
queryFn: () =>
getRecordsInternal(
{
- ens: params?.ens || '',
+ ens: _ens || '',
chainId: _chainId,
},
true
),
enabled:
- Boolean(params?.ens) &&
+ Boolean(_ens) &&
Boolean(_chainId) &&
Boolean(_providerUrl) &&
+ Boolean(validateEns(_ens)) &&
Boolean(_enabled),
});
diff --git a/packages/@justaname.id/react/src/lib/hooks/resolver/useSetNameHashJustaNameResolver.ts b/packages/@justaname.id/react/src/lib/hooks/resolver/useSetNameHashJustaNameResolver.ts
index 6bc1e94f..b20ef502 100644
--- a/packages/@justaname.id/react/src/lib/hooks/resolver/useSetNameHashJustaNameResolver.ts
+++ b/packages/@justaname.id/react/src/lib/hooks/resolver/useSetNameHashJustaNameResolver.ts
@@ -1,7 +1,6 @@
'use client';
import { useMutation } from '@tanstack/react-query';
-import { ethers } from 'ethers';
import { useEffect, useMemo } from 'react';
import {
useReadContract,
@@ -11,6 +10,7 @@ import {
} from 'wagmi';
import { useOffchainResolvers } from '../offchainResolver/useOffchainResolvers';
import { useMountedAccount } from '../account/useMountedAccount';
+import { getAddress, namehash } from '../../helpers/ethersCompat';
const REGISTRY_ADDRESS = '0x00000000000C2E074eC69A0dFb2997BA6C7d2e1e';
const SEPOLIA_REGISTRAR_ADDRESS = '0xA0a1AbcDAe1a2a4A2EF8e9113Ff0e02DD81DC0C6';
@@ -120,12 +120,14 @@ export const useSetNameHashJustaNameResolver = <
T = any
>(): UseSetNameHashJustaNameResolver => {
const { chainId, address } = useMountedAccount();
- const { offchainResolvers, isOffchainResolversPending } = useOffchainResolvers();
+ const { offchainResolvers, isOffchainResolversPending } =
+ useOffchainResolvers();
const currentResolver = useMemo(() => {
if (!chainId || !offchainResolvers || isOffchainResolversPending) return;
- return offchainResolvers?.offchainResolvers.find((resolver) => resolver.chainId === chainId)
- ?.resolverAddress;
+ return offchainResolvers?.offchainResolvers.find(
+ (resolver) => resolver.chainId === chainId
+ )?.resolverAddress;
}, [offchainResolvers, chainId, isOffchainResolversPending]);
const {
@@ -136,11 +138,7 @@ export const useSetNameHashJustaNameResolver = <
address: REGISTRY_ADDRESS,
abi: recordExistsABI,
functionName: 'recordExists',
- args: [
- ethers.namehash(
- ethers.getAddress(address ?? '').substring(2) + '.addr.reverse'
- ),
- ],
+ args: [namehash(getAddress(address ?? '').substring(2) + '.addr.reverse')],
chainId: chainId,
});
@@ -149,7 +147,7 @@ export const useSetNameHashJustaNameResolver = <
chainId === 1 ? MAINNET_REGISTRAR_ADDRESS : SEPOLIA_REGISTRAR_ADDRESS,
abi: setClaimWithResolverABI,
functionName: 'claimWithResolver',
- args: [ethers.getAddress(address ?? ''), currentResolver],
+ args: [getAddress(address ?? ''), currentResolver],
chainId: chainId,
query: {
enabled: recordExistsStatus === 'success' && recordExistsConfig === false,
@@ -164,11 +162,7 @@ export const useSetNameHashJustaNameResolver = <
address: REGISTRY_ADDRESS,
abi: getResolverABI,
functionName: 'resolver',
- args: [
- ethers.namehash(
- ethers.getAddress(address ?? '').substring(2) + '.addr.reverse'
- ),
- ],
+ args: [namehash(getAddress(address ?? '').substring(2) + '.addr.reverse')],
chainId: chainId,
query: {
enabled: recordExistsStatus === 'success' && recordExistsConfig === true,
@@ -180,9 +174,7 @@ export const useSetNameHashJustaNameResolver = <
abi: setResolverABI,
functionName: 'setResolver',
args: [
- ethers.namehash(
- ethers.getAddress(address ?? '').substring(2) + '.addr.reverse'
- ),
+ namehash(getAddress(address ?? '').substring(2) + '.addr.reverse'),
currentResolver,
],
chainId: chainId,
diff --git a/packages/@justaname.id/react/src/lib/hooks/signIn/useEnsAuth.ts b/packages/@justaname.id/react/src/lib/hooks/signIn/useEnsAuth.ts
index 989783ad..24707001 100644
--- a/packages/@justaname.id/react/src/lib/hooks/signIn/useEnsAuth.ts
+++ b/packages/@justaname.id/react/src/lib/hooks/signIn/useEnsAuth.ts
@@ -4,6 +4,7 @@ import { useJustaName } from '../../providers';
import { ChainId } from '@justaname.id/sdk';
import { defaultOptions } from '../../query';
import axios from 'axios';
+import { isParseable } from '../../helpers/isParseable';
export const buildEnsAuthKey = (backendUrl: string) => ['ENS_AUTH', backendUrl];
@@ -17,6 +18,7 @@ export interface UseEnsAuthParams {
backendUrl?: string;
currentEnsRoute?: string;
enabled?: boolean;
+ local?: boolean;
}
export interface UseEnsAuthReturn {
@@ -45,17 +47,28 @@ export const useEnsAuth = (
() => _backendUrl + _currentEnsRoute,
[_backendUrl, _currentEnsRoute]
);
+
const query = useQuery({
...defaultOptions,
retry: 0,
queryKey: buildEnsAuthKey(_backendUrl),
queryFn: async () => {
try {
+ if (params?.local) {
+ const response = localStorage.getItem('ENS_AUTH') || '';
+ if (isParseable(response)) {
+ return JSON.parse(response);
+ } else {
+ localStorage.removeItem('ENS_AUTH');
+ }
+ return null;
+ }
+
const response = await axios.get(currentEnsEndpoint, {
headers: {
'Content-Type': 'application/json',
},
- withCredentials: true, // Similar to 'credentials: include' in fetch
+ withCredentials: true,
});
return response.data;
diff --git a/packages/@justaname.id/react/src/lib/hooks/signIn/useEnsNonce.ts b/packages/@justaname.id/react/src/lib/hooks/signIn/useEnsNonce.ts
index def93b8c..314d3a86 100644
--- a/packages/@justaname.id/react/src/lib/hooks/signIn/useEnsNonce.ts
+++ b/packages/@justaname.id/react/src/lib/hooks/signIn/useEnsNonce.ts
@@ -1,7 +1,12 @@
import { useMemo } from 'react';
import { useJustaName } from '../../providers';
-import { useQuery } from '@tanstack/react-query';
+import {
+ QueryObserverResult,
+ RefetchOptions,
+ useQuery,
+} from '@tanstack/react-query';
import { defaultOptions } from '../../query';
+import { useMountedAccount } from '../account';
export const buildNonceKey = (
backendUrl: string,
@@ -12,13 +17,15 @@ export const buildNonceKey = (
export interface UseEnsNonceParams {
signinNonceRoute?: string;
backendUrl?: string;
- address?: string;
+ // address?: string;
enabled?: boolean;
}
export interface UseEnsNonceResult {
nonce: string | undefined;
- refetchNonce: () => void;
+ refetchNonce: (
+ options?: RefetchOptions | undefined
+ ) => Promise>;
isNoncePending: boolean;
isNonceLoading: boolean;
isNonceFetching: boolean;
@@ -26,6 +33,7 @@ export interface UseEnsNonceResult {
export const useEnsNonce = (params?: UseEnsNonceParams): UseEnsNonceResult => {
const { backendUrl, routes } = useJustaName();
+ const { address } = useMountedAccount();
const _enabled = params?.enabled !== undefined ? params.enabled : true;
const _backendUrl = useMemo(
() => params?.backendUrl || backendUrl || '',
@@ -44,11 +52,7 @@ export const useEnsNonce = (params?: UseEnsNonceParams): UseEnsNonceResult => {
...defaultOptions,
retry: 0,
staleTime: Infinity,
- queryKey: buildNonceKey(
- _backendUrl,
- _signinNonceRoute,
- params?.address || ''
- ),
+ queryKey: buildNonceKey(_backendUrl, _signinNonceRoute, address || ''),
queryFn: async () => {
const nonceResponse = await fetch(nonceEndpoint, {
credentials: 'include',
@@ -60,7 +64,7 @@ export const useEnsNonce = (params?: UseEnsNonceParams): UseEnsNonceResult => {
return nonceResponse.text();
},
- enabled: Boolean(params?.address) && Boolean(_enabled),
+ enabled: Boolean(address) && Boolean(_enabled),
});
return {
diff --git a/packages/@justaname.id/react/src/lib/hooks/signIn/useEnsSignIn.ts b/packages/@justaname.id/react/src/lib/hooks/signIn/useEnsSignIn.ts
index 9184d4df..a076079d 100644
--- a/packages/@justaname.id/react/src/lib/hooks/signIn/useEnsSignIn.ts
+++ b/packages/@justaname.id/react/src/lib/hooks/signIn/useEnsSignIn.ts
@@ -20,6 +20,7 @@ export interface UseEnsSignInParams
signinNonceRoute?: string;
signinRoute?: string;
currentEnsRoute?: string;
+ local?: boolean;
}
export interface UseEnsSignInResult {
@@ -56,28 +57,48 @@ export const useEnsSignIn = (
() => params?.currentEnsRoute || routes.currentEnsRoute,
[routes.currentEnsRoute, params?.currentEnsRoute]
);
+ const _signinNonceRoute = useMemo(
+ () => params?.signinNonceRoute || routes.signinNonceRoute,
+ [routes.signinNonceRoute, params?.signinNonceRoute]
+ );
const { refreshEnsAuth } = useEnsAuth({
backendUrl: _backendUrl,
currentEnsRoute: _currentEnsRoute,
+ local: params?.local,
});
const { nonce, refetchNonce } = useEnsNonce({
- backendUrl: params?.backendUrl,
- signinNonceRoute: params?.signinNonceRoute,
- address,
+ backendUrl: _backendUrl,
+ signinNonceRoute: _signinNonceRoute,
+ enabled: !params?.local,
});
const mutation = useMutation({
mutationFn: async (_params: UseEnsSignInFunctionParams) => {
- if (!address) {
- throw new Error('No address found');
- }
+ try {
+ if (!address) {
+ throw new Error('No address found');
+ }
- if (!nonce) {
- throw new Error('No nonce found');
- }
+ if (params?.local) {
+ localStorage.setItem(
+ 'ENS_AUTH',
+ JSON.stringify({
+ ens: _params.ens,
+ chainId,
+ address,
+ })
+ );
+
+ refreshEnsAuth();
+
+ return 'success';
+ }
+
+ if (!nonce) {
+ throw new Error('No nonce found');
+ }
- try {
const message = justaname.signIn.requestSignIn({
ens: _params.ens,
ttl: config?.signInTtl,
@@ -105,11 +126,15 @@ export const useEnsSignIn = (
credentials: 'include',
});
+ if (response.status !== 200) {
+ throw new Error('Failed to sign in');
+ }
+
refreshEnsAuth();
return response.text();
} catch (e) {
- refetchNonce();
+ await refetchNonce();
throw e;
}
},
diff --git a/packages/@justaname.id/react/src/lib/hooks/signIn/useEnsSignOut.ts b/packages/@justaname.id/react/src/lib/hooks/signIn/useEnsSignOut.ts
index 085fbf29..34cd468b 100644
--- a/packages/@justaname.id/react/src/lib/hooks/signIn/useEnsSignOut.ts
+++ b/packages/@justaname.id/react/src/lib/hooks/signIn/useEnsSignOut.ts
@@ -16,6 +16,7 @@ export interface UseEnsSignOutParams {
signoutRoute?: string;
currentEnsRoute?: string;
signinNonceRoute?: string;
+ local?: boolean;
}
export const useEnsSignOut = (
@@ -43,26 +44,33 @@ export const useEnsSignOut = (
[routes.signinNonceRoute, params?.signinNonceRoute]
);
- const { refreshEnsAuth, connectedEns } = useEnsAuth({
+ const { refreshEnsAuth } = useEnsAuth({
backendUrl: _backendUrl,
currentEnsRoute: _currentEnsRoute,
+ local: params?.local,
});
const { refetchNonce } = useEnsNonce({
backendUrl: _backendUrl,
signinNonceRoute: _signinNonceRoute,
- address: connectedEns?.address,
+ enabled: !params?.local,
});
const mutation = useMutation({
mutationFn: async () => {
+ if (params?.local) {
+ localStorage.removeItem('ENS_AUTH');
+ refreshEnsAuth();
+ return;
+ }
+
await fetch(signoutEndpoint, {
method: 'POST',
credentials: 'include',
});
+ await refetchNonce();
refreshEnsAuth();
- refetchNonce();
},
});
diff --git a/packages/@justaname.id/react/src/lib/providers/JustaNameProvider.tsx b/packages/@justaname.id/react/src/lib/providers/JustaNameProvider.tsx
index 2b49b9cb..b3a690a3 100644
--- a/packages/@justaname.id/react/src/lib/providers/JustaNameProvider.tsx
+++ b/packages/@justaname.id/react/src/lib/providers/JustaNameProvider.tsx
@@ -68,8 +68,8 @@ export const JustaNameProvider: FC = ({
const { chainId } = useMountedAccount();
const defaultChain = useMemo(() => {
- return !chainId
- ? undefined
+ return !chainId === undefined
+ ? 1
: chainId !== 1 && chainId !== 11155111
? 1
: chainId;
diff --git a/packages/@justaname.id/sdk/CHANGELOG.md b/packages/@justaname.id/sdk/CHANGELOG.md
index c520ec0c..0be6bf0c 100644
--- a/packages/@justaname.id/sdk/CHANGELOG.md
+++ b/packages/@justaname.id/sdk/CHANGELOG.md
@@ -1,3 +1,114 @@
+## 0.2.155 (2024-12-03)
+
+
+### 🚀 Features
+
+- sign in optional ([3df90a7](https://github.com/JustaName-id/JustaName-sdk/commit/3df90a7))
+
+
+### 🧱 Updated Dependencies
+
+- Updated @justaname.id/siwens to 0.0.88
+
+
+### ❤️ Thank You
+
+- HadiKhai
+
+## 0.2.154 (2024-12-02)
+
+
+### 🧱 Updated Dependencies
+
+- Updated @justaname.id/siwens to 0.0.87
+
+## 0.2.153 (2024-12-01)
+
+
+### 🚀 Features
+
+- support ethers 5 and ethers 6 ([f82ab13](https://github.com/JustaName-id/JustaName-sdk/commit/f82ab13))
+
+
+### 🧱 Updated Dependencies
+
+- Updated @justaname.id/siwens to 0.0.86
+
+
+### ❤️ Thank You
+
+- HadiKhai
+
+## 0.2.152 (2024-11-29)
+
+
+### 🧱 Updated Dependencies
+
+- Updated @justaname.id/siwens to 0.0.85
+
+## 0.2.151 (2024-11-29)
+
+
+### 🧱 Updated Dependencies
+
+- Updated @justaname.id/siwens to 0.0.84
+
+## 0.2.150 (2024-11-29)
+
+
+### 🧱 Updated Dependencies
+
+- Updated @justaname.id/siwens to 0.0.83
+
+## 0.2.149 (2024-11-29)
+
+
+### 🧱 Updated Dependencies
+
+- Updated @justaname.id/siwens to 0.0.82
+
+## 0.2.148 (2024-11-29)
+
+
+### 🧱 Updated Dependencies
+
+- Updated @justaname.id/siwens to 0.0.81
+
+## 0.2.147 (2024-11-29)
+
+
+### 🚀 Features
+
+- efp ([36fcc153](https://github.com/JustaName-id/JustaName-sdk/commit/36fcc153))
+
+- console fixes ([358b3a0e](https://github.com/JustaName-id/JustaName-sdk/commit/358b3a0e))
+
+- added docs and the sign in should only show ens set to default resolver or justaname resolver only ([a3bcecaa](https://github.com/JustaName-id/JustaName-sdk/commit/a3bcecaa))
+
+- sdk signin fix for aa wallets ([52944a72](https://github.com/JustaName-id/JustaName-sdk/commit/52944a72))
+
+- enabled in hooks and siwens fix and coinbase fix ([c3fb455e](https://github.com/JustaName-id/JustaName-sdk/commit/c3fb455e))
+
+- cache provider url to reduce calls ([d4943d0b](https://github.com/JustaName-id/JustaName-sdk/commit/d4943d0b))
+
+
+### 🩹 Fixes
+
+- update rest call and ui fixes ([81b05f29](https://github.com/JustaName-id/JustaName-sdk/commit/81b05f29))
+
+- justaname network and widget package json ([6afe04ce](https://github.com/JustaName-id/JustaName-sdk/commit/6afe04ce))
+
+
+### 🧱 Updated Dependencies
+
+- Updated @justaname.id/siwens to 0.0.80
+
+
+### ❤️ Thank You
+
+- anthony2399 @anthony23991
+- HadiKhai
+
## 0.2.146 (2024-11-15)
diff --git a/packages/@justaname.id/sdk/package.json b/packages/@justaname.id/sdk/package.json
index a03d998a..33222e62 100644
--- a/packages/@justaname.id/sdk/package.json
+++ b/packages/@justaname.id/sdk/package.json
@@ -1,8 +1,8 @@
{
"name": "@justaname.id/sdk",
- "version": "0.2.146",
+ "version": "0.2.155",
"dependencies": {
- "@justaname.id/siwens": "0.0.79",
+ "@justaname.id/siwens": "0.0.88",
"axios": "^1.6.0",
"qs": "^6.12.0"
},
@@ -10,7 +10,7 @@
"jest": "^29.4.1"
},
"peerDependencies": {
- "ethers": ">=6.0.0",
+ "ethers": "^5.6.8 || ^6.0.8",
"siwe": ">=2.0.0",
"viem": ">=2.0.0"
},
diff --git a/packages/@justaname.id/sdk/src/lib/justaname/index.ts b/packages/@justaname.id/sdk/src/lib/justaname/index.ts
index be7d760c..84da9a6e 100644
--- a/packages/@justaname.id/sdk/src/lib/justaname/index.ts
+++ b/packages/@justaname.id/sdk/src/lib/justaname/index.ts
@@ -14,8 +14,8 @@ import {
Subnames,
} from '../features';
import { InvalidConfigurationException } from '../errors/InvalidConfiguration.exception';
-import { ethers } from 'ethers';
import { providerUrlChainIdLoadingMap, providerUrlChainIdMap } from '../memory';
+import { getJsonRpcProvider } from '../utils/ethersCompat';
/**
* The main class for the JustaName SDK.
@@ -162,11 +162,11 @@ export class JustaName {
const defaultMainnetProviderUrl = 'https://cloudflare-eth.com';
const defaultTestnetProviderUrl = 'https://rpc.sepolia.org';
- const defaultMainnetProvider = new ethers.JsonRpcProvider(
+ const defaultMainnetProvider = getJsonRpcProvider(
defaultMainnetProviderUrl,
1
);
- const defaultTestnetProvider = new ethers.JsonRpcProvider(
+ const defaultTestnetProvider = getJsonRpcProvider(
defaultTestnetProviderUrl,
11155111
);
@@ -184,7 +184,7 @@ export class JustaName {
},
// {
// chainId: 31337 as ChainId,
- // provider: new ethers.JsonRpcProvider('http://localhost:8545'),
+ // provider: getJsonRpcProvider('http://localhost:8545'),
// providerUrl: 'http://localhost:8545',
// },
] as NetworksWithProvider;
@@ -194,7 +194,7 @@ export class JustaName {
if (network && network?.providerUrl) {
return {
chainId: network.chainId,
- provider: new ethers.JsonRpcProvider(network.providerUrl),
+ provider: getJsonRpcProvider(network.providerUrl),
providerUrl: network.providerUrl,
};
} else {
@@ -256,7 +256,7 @@ export class JustaName {
}
}
- const provider = new ethers.JsonRpcProvider(network.providerUrl);
+ const provider = getJsonRpcProvider(network.providerUrl);
provider.getNetwork().then((_network) => {
if (network.chainId.toString() !== _network.chainId.toString()) {
throw new InvalidConfigurationException(
diff --git a/packages/@justaname.id/sdk/src/lib/types/justaname/configuration.ts b/packages/@justaname.id/sdk/src/lib/types/justaname/configuration.ts
index 227c8129..344bc654 100644
--- a/packages/@justaname.id/sdk/src/lib/types/justaname/configuration.ts
+++ b/packages/@justaname.id/sdk/src/lib/types/justaname/configuration.ts
@@ -1,5 +1,5 @@
+import { JsonRpcProvider } from '../../utils/ethersCompat';
import { ChainId } from '../common';
-import { JsonRpcProvider } from 'ethers';
export interface NetworkWithProvider
extends Network {
diff --git a/packages/@justaname.id/sdk/src/lib/utils/ethersCompat.ts b/packages/@justaname.id/sdk/src/lib/utils/ethersCompat.ts
new file mode 100644
index 00000000..682e9f25
--- /dev/null
+++ b/packages/@justaname.id/sdk/src/lib/utils/ethersCompat.ts
@@ -0,0 +1,51 @@
+// inspired by spruceid siwe: https://github.com/spruceid/siwe/blob/main/packages/siwe/lib/ethersCompat.ts
+
+import { ethers } from 'ethers';
+
+// @ts-expect-error -- compatibility hack
+type ProviderV5 = ethers.providers.Provider;
+type ProviderV6 = ethers.Provider;
+// @ts-expect-error -- compatibility hack
+type JsonRpcProviderV5 = ethers.providers.JsonRpcProvider;
+type JsonRpcProviderV6 = ethers.JsonRpcProvider;
+
+export type Provider = ProviderV6 extends undefined ? ProviderV5 : ProviderV6;
+export type JsonRpcProvider = JsonRpcProviderV6 extends undefined
+ ? JsonRpcProviderV5
+ : JsonRpcProviderV6;
+
+interface EthersCompat {
+ namehash?: (name: string) => string;
+ getAddress?: (address: string) => string;
+ JsonRpcProvider?: new (...args: any[]) => JsonRpcProvider;
+ utils: {
+ namehash: (name: string) => string;
+ getAddress: (address: string) => string;
+ };
+ providers: {
+ JsonRpcProvider: new (...args: any[]) => JsonRpcProvider;
+ };
+}
+
+const ethersCompat = ethers as unknown as EthersCompat;
+
+export const getJsonRpcProvider = (
+ providerUrl?: string,
+ chainId?: number
+): JsonRpcProvider => {
+ if ('JsonRpcProvider' in ethersCompat) {
+ return new ethersCompat.JsonRpcProvider!(providerUrl, chainId);
+ } else {
+ return new ethersCompat.providers.JsonRpcProvider(providerUrl, chainId);
+ }
+};
+
+export const namehash: (name: string) => string =
+ 'namehash' in ethersCompat
+ ? ethersCompat.namehash!
+ : ethersCompat.utils.namehash;
+
+export const getAddress: (address: string) => string =
+ 'getAddress' in ethersCompat
+ ? ethersCompat.getAddress!
+ : ethersCompat.utils.getAddress;
diff --git a/packages/@justaname.id/siwens/CHANGELOG.md b/packages/@justaname.id/siwens/CHANGELOG.md
index 29c21301..36acbe66 100644
--- a/packages/@justaname.id/siwens/CHANGELOG.md
+++ b/packages/@justaname.id/siwens/CHANGELOG.md
@@ -1,3 +1,73 @@
+## 0.0.88 (2024-12-03)
+
+
+### 🚀 Features
+
+- sign in optional ([3df90a7](https://github.com/JustaName-id/JustaName-sdk/commit/3df90a7))
+
+
+### ❤️ Thank You
+
+- HadiKhai
+
+## 0.0.87 (2024-12-02)
+
+This was a version bump only for @justaname.id/siwens to align it with other projects, there were no code changes.
+
+## 0.0.86 (2024-12-01)
+
+
+### 🚀 Features
+
+- support ethers 5 and ethers 6 ([f82ab13](https://github.com/JustaName-id/JustaName-sdk/commit/f82ab13))
+
+
+### ❤️ Thank You
+
+- HadiKhai
+
+## 0.0.85 (2024-11-29)
+
+This was a version bump only for @justaname.id/siwens to align it with other projects, there were no code changes.
+
+## 0.0.84 (2024-11-29)
+
+This was a version bump only for @justaname.id/siwens to align it with other projects, there were no code changes.
+
+## 0.0.83 (2024-11-29)
+
+This was a version bump only for @justaname.id/siwens to align it with other projects, there were no code changes.
+
+## 0.0.82 (2024-11-29)
+
+This was a version bump only for @justaname.id/siwens to align it with other projects, there were no code changes.
+
+## 0.0.81 (2024-11-29)
+
+This was a version bump only for @justaname.id/siwens to align it with other projects, there were no code changes.
+
+## 0.0.80 (2024-11-29)
+
+
+### 🚀 Features
+
+- added docs and the sign in should only show ens set to default resolver or justaname resolver only ([a3bcecaa](https://github.com/JustaName-id/JustaName-sdk/commit/a3bcecaa))
+
+- sdk signin fix for aa wallets ([52944a72](https://github.com/JustaName-id/JustaName-sdk/commit/52944a72))
+
+- enabled in hooks and siwens fix and coinbase fix ([c3fb455e](https://github.com/JustaName-id/JustaName-sdk/commit/c3fb455e))
+
+
+### 🩹 Fixes
+
+- update rest call and ui fixes ([81b05f29](https://github.com/JustaName-id/JustaName-sdk/commit/81b05f29))
+
+
+### ❤️ Thank You
+
+- anthony2399 @anthony23991
+- HadiKhai
+
## 0.0.79 (2024-11-15)
This was a version bump only for @justaname.id/siwens to align it with other projects, there were no code changes.
diff --git a/packages/@justaname.id/siwens/README.md b/packages/@justaname.id/siwens/README.md
index 067c7dee..727d6e1b 100644
--- a/packages/@justaname.id/siwens/README.md
+++ b/packages/@justaname.id/siwens/README.md
@@ -43,54 +43,60 @@ yarn add @justaname.id/siwens
### Example Usage
```typescript
-import { SIWENS, InvalidDomainException, InvalidENSException, InvalidStatementException, InvalidTimeException } f, InvalidDomainException, InvalidENSException, InvalidStatementException, InvalidTimeException } from '@justaname.id/siwens';rom '@justaname.id/siwens';
-import { ethers } from 'ethers';
+import { SIWENS, InvalidENSException } from '@justaname.id/siwens';
+import { Wallet } from 'ethers';
// Define your provider URL (e.g., Infura)
-const providerUrl = 'https://mainnet.infura.io/v3/YOUR_INFURA_KEY';
+const infuraProjectId = 'YOUR_INFURA_PROJECT_ID';
+const providerUrl = 'https://mainnet.infura.io/v3/' + infuraProjectId;
-const signer = new ethers.Wallet('YOUR_PRIVATE_KEY_ENS_HOLDER')
+// const signer = Wallet.createRandom();
+const signer = new Wallet('YOUR_PRIVATE_KEY');
async function signInUser() {
const siwens = new SIWENS({
params: {
- domain: 'example.eth', // The domain you're authenticating for
+ domain: 'example.com', // The domain you're authenticating for
+ uri: 'https://example.com', // The URI of the dApp
+ chainId: 1, // The chain ID of the network
ttl: 3600000, // Time-to-Live (TTL) in milliseconds (1 hour)
ens: 'user.example.eth', // The ENS name being used
statement: 'Signing into dApp', // Optional custom sign-in statement
+ address: signer.address
},
providerUrl
- });
+ });
const message = await siwens.prepareMessage();
const signature = await signer.signMessage(message);
- return signature;
+ return {signature, message};
}
// Verifying a user's sign-in request
-async function verifyUserSignature(signature: string, message: string) {
- try {
- const siwe = new SIWENS({
- params: message,
- providerUrl
- })
-
- const verification = await siwe.verifySignature({
- signature: signature,
- });
-
- console.log('ENS Sign-in successful!', verification.ens);
- } catch (error) {
- if (error instanceof InvalidENSException) {
- console.error('ENS Verification Failed:', error.message);
- } else {
- console.error('Error during verification:', error.message);
- }
- }
+async function verifyUserSignature(signature, message) {
+ try {
+ const siwe = new SIWENS({
+ params: message,
+ providerUrl
+ })
+
+ const verification = await siwe.verify({
+ signature: signature,
+ });
+
+ console.log('ENS Sign-in successful!', verification.ens);
+ } catch (error) {
+ console.error('Error during verification:', error);
+ if (error instanceof InvalidENSException) {
+ console.error('ENS Verification Failed:', error.message);
+ } else {
+ console.error('Error during verification:', error);
+ }
+ }
}
// Example usage
-signInUser().then(async (signature) => {
- await verifyUserSignature(signature, 'Signing into dApp');
+signInUser().then(async ({message, signature}) => {
+ await verifyUserSignature(signature, message);
});
```
diff --git a/packages/@justaname.id/siwens/package.json b/packages/@justaname.id/siwens/package.json
index f9bd6a16..e7616056 100644
--- a/packages/@justaname.id/siwens/package.json
+++ b/packages/@justaname.id/siwens/package.json
@@ -1,8 +1,8 @@
{
"name": "@justaname.id/siwens",
- "version": "0.0.79",
+ "version": "0.0.88",
"peerDependencies": {
- "ethers": ">=6.0.0",
+ "ethers": "^5.6.8 || ^6.0.8",
"siwe": ">=2.0.0"
},
"exports": {
diff --git a/packages/@justaname.id/siwens/src/lib/siwens/siwens.ts b/packages/@justaname.id/siwens/src/lib/siwens/siwens.ts
index d12c68ca..c85ddcb7 100644
--- a/packages/@justaname.id/siwens/src/lib/siwens/siwens.ts
+++ b/packages/@justaname.id/siwens/src/lib/siwens/siwens.ts
@@ -1,4 +1,3 @@
-import { JsonRpcProvider } from 'ethers';
import {
generateNonce,
SiweMessage,
@@ -19,6 +18,7 @@ import {
extractDataFromStatement,
} from '../utils';
import { toASCII, toUnicode } from 'punycode';
+import { getJsonRpcProvider, JsonRpcProvider } from '../utils/ethersCompat';
export interface SiwensResponse extends SiweResponse {
ens: string;
@@ -50,7 +50,7 @@ export class SIWENS extends SiweMessage {
if (!providerUrl) {
throw InvalidConfigurationException.providerUrlRequired();
}
- this.provider = new JsonRpcProvider(providerUrl);
+ this.provider = getJsonRpcProvider(providerUrl);
this.providerUrl = providerUrl;
return;
}
@@ -91,12 +91,12 @@ export class SIWENS extends SiweMessage {
expirationTime,
});
this.providerUrl = providerUrl;
- this.provider = new JsonRpcProvider(providerUrl);
+ this.provider = getJsonRpcProvider(providerUrl);
}
override async verify(
params: VerifyParams,
- opts: VerifyOpts
+ opts?: VerifyOpts
): Promise {
let verification: SiweResponse;
diff --git a/packages/@justaname.id/siwens/src/lib/utils/ethersCompat.ts b/packages/@justaname.id/siwens/src/lib/utils/ethersCompat.ts
new file mode 100644
index 00000000..682e9f25
--- /dev/null
+++ b/packages/@justaname.id/siwens/src/lib/utils/ethersCompat.ts
@@ -0,0 +1,51 @@
+// inspired by spruceid siwe: https://github.com/spruceid/siwe/blob/main/packages/siwe/lib/ethersCompat.ts
+
+import { ethers } from 'ethers';
+
+// @ts-expect-error -- compatibility hack
+type ProviderV5 = ethers.providers.Provider;
+type ProviderV6 = ethers.Provider;
+// @ts-expect-error -- compatibility hack
+type JsonRpcProviderV5 = ethers.providers.JsonRpcProvider;
+type JsonRpcProviderV6 = ethers.JsonRpcProvider;
+
+export type Provider = ProviderV6 extends undefined ? ProviderV5 : ProviderV6;
+export type JsonRpcProvider = JsonRpcProviderV6 extends undefined
+ ? JsonRpcProviderV5
+ : JsonRpcProviderV6;
+
+interface EthersCompat {
+ namehash?: (name: string) => string;
+ getAddress?: (address: string) => string;
+ JsonRpcProvider?: new (...args: any[]) => JsonRpcProvider;
+ utils: {
+ namehash: (name: string) => string;
+ getAddress: (address: string) => string;
+ };
+ providers: {
+ JsonRpcProvider: new (...args: any[]) => JsonRpcProvider;
+ };
+}
+
+const ethersCompat = ethers as unknown as EthersCompat;
+
+export const getJsonRpcProvider = (
+ providerUrl?: string,
+ chainId?: number
+): JsonRpcProvider => {
+ if ('JsonRpcProvider' in ethersCompat) {
+ return new ethersCompat.JsonRpcProvider!(providerUrl, chainId);
+ } else {
+ return new ethersCompat.providers.JsonRpcProvider(providerUrl, chainId);
+ }
+};
+
+export const namehash: (name: string) => string =
+ 'namehash' in ethersCompat
+ ? ethersCompat.namehash!
+ : ethersCompat.utils.namehash;
+
+export const getAddress: (address: string) => string =
+ 'getAddress' in ethersCompat
+ ? ethersCompat.getAddress!
+ : ethersCompat.utils.getAddress;
diff --git a/packages/@justverified/plugin/CHANGELOG.md b/packages/@justverified/plugin/CHANGELOG.md
index 32447882..67dfe942 100644
--- a/packages/@justverified/plugin/CHANGELOG.md
+++ b/packages/@justverified/plugin/CHANGELOG.md
@@ -1,3 +1,70 @@
+## 0.0.93 (2024-12-03)
+
+This was a version bump only for @justverified/plugin to align it with other projects, there were no code changes.
+
+## 0.0.92 (2024-12-02)
+
+This was a version bump only for @justverified/plugin to align it with other projects, there were no code changes.
+
+## 0.0.91 (2024-12-01)
+
+This was a version bump only for @justverified/plugin to align it with other projects, there were no code changes.
+
+## 0.0.90 (2024-11-29)
+
+This was a version bump only for @justverified/plugin to align it with other projects, there were no code changes.
+
+## 0.0.89 (2024-11-29)
+
+This was a version bump only for @justverified/plugin to align it with other projects, there were no code changes.
+
+## 0.0.88 (2024-11-29)
+
+This was a version bump only for @justverified/plugin to align it with other projects, there were no code changes.
+
+## 0.0.87 (2024-11-29)
+
+This was a version bump only for @justverified/plugin to align it with other projects, there were no code changes.
+
+## 0.0.86 (2024-11-29)
+
+This was a version bump only for @justverified/plugin to align it with other projects, there were no code changes.
+
+## 0.0.85 (2024-11-29)
+
+
+### 🚀 Features
+
+- remove mapps from justverified ([2898c521](https://github.com/JustaName-id/JustaName-sdk/commit/2898c521))
+
+- efp ([36fcc153](https://github.com/JustaName-id/JustaName-sdk/commit/36fcc153))
+
+- efp and storybook for react sdk ([f0c5c7a0](https://github.com/JustaName-id/JustaName-sdk/commit/f0c5c7a0))
+
+- console fixes ([358b3a0e](https://github.com/JustaName-id/JustaName-sdk/commit/358b3a0e))
+
+- added docs and the sign in should only show ens set to default resolver or justaname resolver only ([a3bcecaa](https://github.com/JustaName-id/JustaName-sdk/commit/a3bcecaa))
+
+- move justweb3 to peer dep in the plugins ([316047cb](https://github.com/JustaName-id/JustaName-sdk/commit/316047cb))
+
+- rainbow and privy examples ([fb2aa7dc](https://github.com/JustaName-id/JustaName-sdk/commit/fb2aa7dc))
+
+- dialog fixes and logo needs to be fixed ([fad47312](https://github.com/JustaName-id/JustaName-sdk/commit/fad47312))
+
+- **widget:** mobile dialogs ([#51](https://github.com/JustaName-id/JustaName-sdk/pull/51))
+
+
+### 🩹 Fixes
+
+- update rest call and ui fixes ([81b05f29](https://github.com/JustaName-id/JustaName-sdk/commit/81b05f29))
+
+
+### ❤️ Thank You
+
+- Anthony Khoury @anthony23991
+- anthony2399 @anthony23991
+- HadiKhai
+
## 0.0.84 (2024-11-15)
This was a version bump only for @justverified/plugin to align it with other projects, there were no code changes.
diff --git a/packages/@justverified/plugin/package.json b/packages/@justverified/plugin/package.json
index ea512de6..27dd8160 100644
--- a/packages/@justverified/plugin/package.json
+++ b/packages/@justverified/plugin/package.json
@@ -1,6 +1,6 @@
{
"name": "@justverified/plugin",
- "version": "0.0.84",
+ "version": "0.0.93",
"dependencies": {
"axios": "^1.6.0",
"lodash": "4.17.21",
diff --git a/packages/@justverified/plugin/src/stories/justverified.stories.tsx b/packages/@justverified/plugin/src/stories/justverified.stories.tsx
index e541a041..d3074875 100644
--- a/packages/@justverified/plugin/src/stories/justverified.stories.tsx
+++ b/packages/@justverified/plugin/src/stories/justverified.stories.tsx
@@ -11,7 +11,6 @@ import { ChainId } from '@justaname.id/sdk';
import { Meta, StoryObj } from '@storybook/react';
import { Button } from '@justweb3/ui';
import {
- JustEnsCard,
JustWeb3Button,
JustWeb3Provider,
JustWeb3ProviderConfig,
@@ -19,6 +18,7 @@ import {
} from '@justweb3/widget';
import '@justweb3/widget/styles.css';
import { JustVerifiedPlugin } from '../lib';
+import { ReactQueryDevtools } from '@tanstack/react-query-devtools';
const queryClient = new QueryClient();
@@ -47,13 +47,14 @@ const JustWeb3Config: JustWeb3ProviderConfig = {
],
openOnWalletConnect: true,
allowedEns: 'all',
- dev: import.meta.env.STORYBOOK_APP_DEV === 'true',
+ // dev: import.meta.env.STORYBOOK_APP_DEV === 'true',
disableOverlay: true,
+ // enableAuth: true,
plugins: [
JustVerifiedPlugin(
- ['twitter', 'github', 'discord'],
+ ['twitter', 'github', 'discord']
// 'http://localhost:3009/verifications/v1'
- 'https://api-staging.justaname.id/verifications/v1'
+ // 'https://api-staging.justaname.id/verifications/v1'
),
],
};
@@ -110,35 +111,36 @@ export const Example = () => {
-
+ {/*
*/}
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+ {/*
*/}
+ {/* */}
+ {/* */}
+ {/* */}
+ {/* */}
+ {/* */}
+ {/* */}
+ {/* */}
+ {/*
*/}
+ {/*
*/}
+ {/* */}
+ {/* */}
+ {/* */}
+ {/* */}
+ {/* */}
+ {/* */}
+ {/*
*/}
+