diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index 572b2b0f..d8517641 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -31,12 +31,14 @@ jobs:
- run: npx nx affected -t lint
- name: Run Tests
env:
- PRIVATE_KEY: ${{ secrets.PRIVATE_KEY }}
- PROVIDER_URL: ${{ secrets.PROVIDER_URL }}
- VALID_SUBNAME: ${{ secrets.VALID_SUBNAME }}
- JUSTANAME_ENVIRONMENT: ${{ secrets.JUSTANAME_ENVIRONMENT }}
- JUSTANAME_TEST_API_KEY: ${{ secrets.JUSTANAME_TEST_API_KEY }}
- JUSTANAME_DEV: ${{ secrets.JUSTANAME_DEV }}
- ENS_DOMAIN: ${{ secrets.ENS_DOMAIN }}
+ SDK_JUSTANAME_ENVIRONMENT: ${{ secrets.SDK_JUSTANAME_ENVIRONMENT }}
+ SDK_JUSTANAME_TEST_API_KEY: ${{ secrets.SDK_JUSTANAME_TEST_API_KEY }}
+ SDK_MAPP_PRIVATE_KEY: ${{ secrets.SDK_MAPP_PRIVATE_KEY }}
+ SDK_PROVIDER_URL: ${{ secrets.SDK_PROVIDER_URL }}
+ SDK_ENS_DOMAIN: ${{ secrets.SDK_ENS_DOMAIN }}
+ SDK_MAPP: ${{ secrets.SDK_MAPP }}
+ SIWENS_PRIVATE_KEY: ${{ secrets.SIWENS_PRIVATE_KEY }}
+ SIWENS_PROVIDER_URL: ${{ secrets.SIWENS_PROVIDER_URL }}
+ SIWENS_VALID_ENS: ${{ secrets.SIWENS_VALID_ENS }}
run: npx nx affected -t test --configuration=ci --passWithNoTests --exclude=justaname-mono-sdk
- run: npx nx affected -t build
\ No newline at end of file
diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml
index 8426f863..7d6c986c 100644
--- a/.github/workflows/release.yml
+++ b/.github/workflows/release.yml
@@ -48,13 +48,15 @@ jobs:
- name: Build and Test
env:
- PRIVATE_KEY: ${{ secrets.PRIVATE_KEY }}
- PROVIDER_URL: ${{ secrets.PROVIDER_URL }}
- VALID_SUBNAME: ${{ secrets.VALID_SUBNAME }}
- JUSTANAME_ENVIRONMENT: ${{ secrets.JUSTANAME_ENVIRONMENT }}
- JUSTANAME_TEST_API_KEY: ${{ secrets.JUSTANAME_TEST_API_KEY }}
- JUSTANAME_DEV: ${{ secrets.JUSTANAME_DEV }}
- ENS_DOMAIN: ${{ secrets.ENS_DOMAIN }}
+ SDK_JUSTANAME_ENVIRONMENT: ${{ secrets.SDK_JUSTANAME_ENVIRONMENT }}
+ SDK_JUSTANAME_TEST_API_KEY: ${{ secrets.SDK_JUSTANAME_TEST_API_KEY }}
+ SDK_MAPP_PRIVATE_KEY: ${{ secrets.SDK_MAPP_PRIVATE_KEY }}
+ SDK_PROVIDER_URL: ${{ secrets.SDK_PROVIDER_URL }}
+ SDK_ENS_DOMAIN: ${{ secrets.SDK_ENS_DOMAIN }}
+ SDK_MAPP: ${{ secrets.SDK_MAPP }}
+ SIWENS_PRIVATE_KEY: ${{ secrets.SIWENS_PRIVATE_KEY }}
+ SIWENS_PROVIDER_URL: ${{ secrets.SIWENS_PROVIDER_URL }}
+ SIWENS_VALID_ENS: ${{ secrets.SIWENS_VALID_ENS }}
run: |
npx nx affected -t lint
npx nx affected -t test --configuration=ci --passWithNoTests --exclude=justaname-mono-sdk
diff --git a/apps/express-trial/project.json b/apps/express-trial/project.json
index aa8252b4..3a84b51f 100644
--- a/apps/express-trial/project.json
+++ b/apps/express-trial/project.json
@@ -36,7 +36,11 @@
"development": {},
"production": {}
},
- "dependsOn": ["lint"]
+ "dependsOn": ["lint",
+ {
+ "projects": ["@justaname.id/sdk"],
+ "target": "build"
+ }]
}
},
"tags": []
diff --git a/apps/react-trial/src/app/app.tsx b/apps/react-trial/src/app/app.tsx
index 9776ade7..b5508491 100644
--- a/apps/react-trial/src/app/app.tsx
+++ b/apps/react-trial/src/app/app.tsx
@@ -1,4 +1,4 @@
-import { SIWJProvider, SIWJProviderConfig } from '@justaname.id/react-signin'
+import { SIWENSProvider, SIWENSProviderConfig } from '@justaname.id/react-signin'
import '@rainbow-me/rainbowkit/styles.css';
import {
getDefaultConfig,
@@ -17,7 +17,7 @@ import { ChainId } from '@justaname.id/sdk';
const queryClient = new QueryClient();
-const JustaNameConfig: SIWJProviderConfig = {
+const JustaNameConfig: SIWENSProviderConfig = {
config: {
chainId: parseInt(import.meta.env.VITE_APP_CHAIN_ID) as ChainId,
origin: import.meta.env.VITE_APP_ORIGIN,
@@ -41,9 +41,9 @@ export function App() {
return (
-
+
-
+
);
diff --git a/apps/with-privy/src/app/app.tsx b/apps/with-privy/src/app/app.tsx
index dd909ac1..36b868c3 100644
--- a/apps/with-privy/src/app/app.tsx
+++ b/apps/with-privy/src/app/app.tsx
@@ -1,4 +1,4 @@
-import { SIWJProvider, SIWJProviderConfig } from '@justaname.id/react-signin'
+import { SIWENSProvider, SIWENSProviderConfig } from '@justaname.id/react-signin'
import '@rainbow-me/rainbowkit/styles.css';
import { http } from 'wagmi';
import {
@@ -12,11 +12,11 @@ import {
import { ChainId } from '@justaname.id/sdk';
import { PrivyProvider, usePrivy } from '@privy-io/react-auth';
import {createConfig, WagmiProvider} from '@privy-io/wagmi';
-import { useSubnameSession } from '@justaname.id/react';
+import { useEnsAuth } from '@justaname.id/react';
const queryClient = new QueryClient();
-const JustaNameConfig: SIWJProviderConfig = {
+const JustaNameConfig: SIWENSProviderConfig = {
config: {
chainId: parseInt(import.meta.env.VITE_APP_CHAIN_ID) as ChainId,
origin: import.meta.env.VITE_APP_ORIGIN,
@@ -31,7 +31,7 @@ const JustaNameConfig: SIWJProviderConfig = {
const Connect = () => {
const { ready, authenticated, user, login, logout } = usePrivy();
- const { subnameSession} = useSubnameSession();
+ const { connectedEns} = useEnsAuth();
if (!ready) {
return null;
}
@@ -57,10 +57,10 @@ const Connect = () => {
)}
{
- subnameSession &&
+ connectedEns &&
@@ -97,9 +97,9 @@ export function App() {
>
-
+
-
+
diff --git a/packages/@justaname.id/react-signin/src/lib/components/Footer/index.tsx b/packages/@justaname.id/react-signin/src/lib/components/Footer/index.tsx
new file mode 100644
index 00000000..823453b2
--- /dev/null
+++ b/packages/@justaname.id/react-signin/src/lib/components/Footer/index.tsx
@@ -0,0 +1,41 @@
+import { A, Flex, JustaNameLogoIcon, SPAN } from '@justaname.id/react-ui';
+
+export const Footer = () => {
+ return(
+
+
+
+ Powered by justaname.id
+
+
+
+
+
+ )
+}
\ No newline at end of file
diff --git a/packages/@justaname.id/react-signin/src/lib/components/index.ts b/packages/@justaname.id/react-signin/src/lib/components/index.ts
index 40743603..ce4c935c 100644
--- a/packages/@justaname.id/react-signin/src/lib/components/index.ts
+++ b/packages/@justaname.id/react-signin/src/lib/components/index.ts
@@ -1,2 +1,3 @@
export * from './SelectSubnameItem';
-export * from './Loading';
\ No newline at end of file
+export * from './Loading';
+export * from './Footer';
\ No newline at end of file
diff --git a/packages/@justaname.id/react-signin/src/lib/modal/LoadingDialog/index.tsx b/packages/@justaname.id/react-signin/src/lib/dialogs/LoadingDialog/index.tsx
similarity index 100%
rename from packages/@justaname.id/react-signin/src/lib/modal/LoadingDialog/index.tsx
rename to packages/@justaname.id/react-signin/src/lib/dialogs/LoadingDialog/index.tsx
diff --git a/packages/@justaname.id/react-signin/src/lib/dialogs/MAppDialog/index.tsx b/packages/@justaname.id/react-signin/src/lib/dialogs/MAppDialog/index.tsx
new file mode 100644
index 00000000..baf43dea
--- /dev/null
+++ b/packages/@justaname.id/react-signin/src/lib/dialogs/MAppDialog/index.tsx
@@ -0,0 +1,202 @@
+import { FC, Fragment, useEffect, useMemo } from 'react';
+import { useAddMAppPermission, useEnsAuth, useIsMAppEnabled, useRecords } from '@justaname.id/react';
+import { Badge, Button, CloseIcon, Dialog, DialogContent, DialogTitle, Flex, H2, P } from '@justaname.id/react-ui';
+import { Footer } from '../../components';
+import { isParseable } from '../../utils';
+import { LoadingDialog } from '../LoadingDialog';
+
+export interface MAppDialogProps {
+ mApp: string;
+ open: boolean;
+ handleOpenDialog: (open: boolean) => void;
+}
+
+export const MAppDialog: FC
= ({
+ mApp,
+ open,
+ handleOpenDialog
+ }) => {
+ const { connectedEns, isLoggedIn, isEnsAuthPending } = useEnsAuth();
+ const { records , isRecordsPending} = useRecords({
+ fullName: mApp || ''
+ });
+ const { isMAppEnabled, refetchIsMAppEnabled , isMAppEnabledPending } = useIsMAppEnabled({
+ subname: connectedEns?.ens || '',
+ mApp
+ });
+ const { addMAppPermission, isAddMAppPermissionPending } = useAddMAppPermission({
+ mApp
+ });
+
+ const mAppDescription = useMemo(() => {
+ return records?.texts?.find((text) => text.key === `mApp_description`)?.value;
+ }, [records]);
+
+ const mAppPermissions = useMemo((): string[] => {
+ console.log(records)
+ if (!records) {
+ return [];
+ }
+
+ const permissions = records?.texts?.find((text) => text.key === `mApp_permissions`)?.value;
+ if (!permissions) {
+ return [];
+ }
+
+ if (!isParseable(permissions)) {
+ return [];
+ }
+
+ const parsedPermissions = JSON.parse(permissions) as string[];
+ if (!Array.isArray(parsedPermissions)) {
+ return [];
+ }
+
+ return parsedPermissions;
+ }, [records]);
+
+ console.log(isMAppEnabled, open)
+ useEffect(() => {
+ if(isLoggedIn){
+
+ if(isMAppEnabledPending || isMAppEnabled === undefined){
+ return
+ }
+
+ handleOpenDialog(!isMAppEnabled)
+ }
+ else{
+ handleOpenDialog(false)
+ }
+ }, [isMAppEnabled, isLoggedIn, isMAppEnabledPending])
+
+ if (( isEnsAuthPending || isRecordsPending || isMAppEnabledPending) && open) {
+ return
+ }
+
+ return (
+
+ );
+};
\ No newline at end of file
diff --git a/packages/@justaname.id/react-signin/src/lib/modal/SIWENSDialog/index.tsx b/packages/@justaname.id/react-signin/src/lib/dialogs/SIWENSDialog/index.tsx
similarity index 92%
rename from packages/@justaname.id/react-signin/src/lib/modal/SIWENSDialog/index.tsx
rename to packages/@justaname.id/react-signin/src/lib/dialogs/SIWENSDialog/index.tsx
index adc4475e..8923fcee 100644
--- a/packages/@justaname.id/react-signin/src/lib/modal/SIWENSDialog/index.tsx
+++ b/packages/@justaname.id/react-signin/src/lib/dialogs/SIWENSDialog/index.tsx
@@ -28,10 +28,11 @@ export const SIWENSDialog: React.FC = ({ open, handleOpenDial
}, [accountSubnames, allowedSubnames, ensDomain]);
+ if(isConnected && isAccountSubnamesPending && open){
+ return
+ }
+
return (
- <>
-
- >
);
};
\ No newline at end of file
diff --git a/packages/@justaname.id/react-signin/src/lib/modal/SelectSubnameDialog/index.tsx b/packages/@justaname.id/react-signin/src/lib/dialogs/SelectSubnameDialog/index.tsx
similarity index 85%
rename from packages/@justaname.id/react-signin/src/lib/modal/SelectSubnameDialog/index.tsx
rename to packages/@justaname.id/react-signin/src/lib/dialogs/SelectSubnameDialog/index.tsx
index 6f33c67d..34306b7d 100644
--- a/packages/@justaname.id/react-signin/src/lib/modal/SelectSubnameDialog/index.tsx
+++ b/packages/@justaname.id/react-signin/src/lib/dialogs/SelectSubnameDialog/index.tsx
@@ -1,27 +1,32 @@
import {
- A,
Badge,
- Button, Dialog, DialogContent, DialogTitle,
+ Button,
+ Dialog,
+ DialogContent,
+ DialogTitle,
Flex,
formatText,
H2,
Input,
- JustaNameLogoIcon,
OrLine,
ProfileIcon,
- SPAN,
CloseIcon
} from '@justaname.id/react-ui';
import {
SubnamesType,
- useAddSubname, useEnsSignIn,
+ useAddSubname,
+ useEnsSignIn,
useIsSubnameAvailable,
- useJustaName, useMountedAccount
+ useJustaName,
+ useMountedAccount
} from '@justaname.id/react';
import React, { useMemo } from 'react';
import styled from 'styled-components';
import { useDebounce } from '../../hooks';
-import { SelectSubnameItem } from '../../components';
+import {
+ Footer,
+ SelectSubnameItem
+} from '../../components';
const TransitionElement = styled.div<{ maxheight: string }>`
max-height: 0;
@@ -212,41 +217,7 @@ export const SelectSubnameDialog: React.FC = ({ subnam
-
-
-
- Powered by justaname.id
-
-
-
-
-
+
diff --git a/packages/@justaname.id/react-signin/src/lib/modal/index.ts b/packages/@justaname.id/react-signin/src/lib/dialogs/index.ts
similarity index 53%
rename from packages/@justaname.id/react-signin/src/lib/modal/index.ts
rename to packages/@justaname.id/react-signin/src/lib/dialogs/index.ts
index ea8f08a4..50e5af67 100644
--- a/packages/@justaname.id/react-signin/src/lib/modal/index.ts
+++ b/packages/@justaname.id/react-signin/src/lib/dialogs/index.ts
@@ -1,3 +1,4 @@
export * from './SIWENSDialog';
export * from './SelectSubnameDialog';
-export * from './LoadingDialog';
\ No newline at end of file
+export * from './LoadingDialog';
+export * from './MAppDialog';
\ No newline at end of file
diff --git a/packages/@justaname.id/react-signin/src/lib/providers/SIWENSProvider/index.tsx b/packages/@justaname.id/react-signin/src/lib/providers/SIWENSProvider/index.tsx
index d73ed05d..65fe25fb 100644
--- a/packages/@justaname.id/react-signin/src/lib/providers/SIWENSProvider/index.tsx
+++ b/packages/@justaname.id/react-signin/src/lib/providers/SIWENSProvider/index.tsx
@@ -10,7 +10,7 @@ import {
UseEnsAuthReturn, EnsSignInParams
} from '@justaname.id/react';
import { JustaThemeProvider, JustaThemeProviderConfig } from '@justaname.id/react-ui';
-import { SIWENSDialog } from '../../modal';
+import { SIWENSDialog } from '../../dialogs';
import { UseMutateAsyncFunction } from '@tanstack/react-query';
export interface SIWENSProviderConfig extends JustaNameProviderConfig, JustaThemeProviderConfig {
diff --git a/packages/@justaname.id/react-signin/src/lib/utils/index.ts b/packages/@justaname.id/react-signin/src/lib/utils/index.ts
new file mode 100644
index 00000000..8055c983
--- /dev/null
+++ b/packages/@justaname.id/react-signin/src/lib/utils/index.ts
@@ -0,0 +1 @@
+export * from './isParseable';
\ No newline at end of file
diff --git a/packages/@justaname.id/react-signin/src/lib/utils/isParseable/index.ts b/packages/@justaname.id/react-signin/src/lib/utils/isParseable/index.ts
new file mode 100644
index 00000000..f62dbf9c
--- /dev/null
+++ b/packages/@justaname.id/react-signin/src/lib/utils/isParseable/index.ts
@@ -0,0 +1,9 @@
+export const isParseable = (value: string): boolean => {
+ try {
+ JSON.parse(value);
+ return true;
+ } catch (e) {
+ console.error(e);
+ return false;
+ }
+}
\ No newline at end of file
diff --git a/packages/@justaname.id/react-signin/src/stories/mApp.stories.tsx b/packages/@justaname.id/react-signin/src/stories/mApp.stories.tsx
new file mode 100644
index 00000000..bcca91e3
--- /dev/null
+++ b/packages/@justaname.id/react-signin/src/stories/mApp.stories.tsx
@@ -0,0 +1,84 @@
+import { Meta, StoryObj } from '@storybook/react';
+import { MAppDialog } from '../lib/dialogs';
+import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
+import { SIWENSProvider, SIWENSProviderConfig, useSignInWithEns } from '../lib';
+import '@rainbow-me/rainbowkit/styles.css';
+import { ConnectButton, getDefaultConfig, RainbowKitProvider } from '@rainbow-me/rainbowkit';
+import { mainnet, sepolia } from 'wagmi/chains';
+import { WagmiProvider } from 'wagmi';
+import { ChainId } from '@justaname.id/sdk';
+import { useState } from 'react';
+
+const queryClient = new QueryClient();
+
+const JustaNameConfig: SIWENSProviderConfig = {
+ config: {
+ chainId: parseInt(import.meta.env.STORYBOOK_APP_CHAIN_ID) as ChainId,
+ origin: import.meta.env.STORYBOOK_APP_ORIGIN,
+ domain: import.meta.env.STORYBOOK_APP_DOMAIN,
+ signIn:{
+ ttl: 1000 * 60 * 60 * 24
+ },
+ },
+ backendUrl: import.meta.env.STORYBOOK_APP_BACKEND_URL,
+ providerUrl: import.meta.env.STORYBOOK_APP_PROVIDER_URL,
+ ensDomain: import.meta.env.STORYBOOK_APP_ENS_DOMAIN,
+ openOnWalletConnect: true,
+ allowedSubnames:'all',
+}
+
+const Session = () => {
+ const { connectedEns, handleOpenSignInDialog, signOut} = useSignInWithEns()
+ const [open, setOpen] = useState(false);
+
+ const handleOpenDialog = (_open: boolean) => {
+ if (_open !== open) {
+ setOpen(_open);
+ }
+ }
+
+ return (
+
+
Subname Session
+ {
+ !connectedEns &&
+ }
+ {
+ connectedEns &&
+ }
+
+
{JSON.stringify(connectedEns, null, 2)}
+
+ )
+}
+
+export const Example = () => {
+
+ const config = getDefaultConfig({
+ appName: 'My RainbowKit App',
+ projectId: 'YOUR_PROJECT_ID',
+ chains: import.meta.env.STORYBOOK_APP_CHAIN_ID === "1" ? [mainnet] : [sepolia],
+ });
+
+ return (
+
+
+
+
+
+
+
+
+
+
+ )
+}
+
+const meta: Meta = {
+ component: Example,
+ title: 'Connect/MAppDialog',
+};
+
+export default meta;
+// @ts-ignore
+type Story = StoryObj
diff --git a/packages/@justaname.id/react-signin/src/stories/signin.stories.tsx b/packages/@justaname.id/react-signin/src/stories/signin.stories.tsx
index e43eb132..1cd8696c 100644
--- a/packages/@justaname.id/react-signin/src/stories/signin.stories.tsx
+++ b/packages/@justaname.id/react-signin/src/stories/signin.stories.tsx
@@ -66,13 +66,9 @@ export const Example = () => {
const meta: Meta = {
component: Example,
title: 'Connect/Wallet',
- tags: ['autodocs'],
};
export default meta;
+// @ts-ignore
type Story = StoryObj
-export const Primary: Story = {
- args: {},
-};
-
diff --git a/packages/@justaname.id/react/src/lib/constants/default-routes/index.ts b/packages/@justaname.id/react/src/lib/constants/default-routes/index.ts
index ec160de8..3717a855 100644
--- a/packages/@justaname.id/react/src/lib/constants/default-routes/index.ts
+++ b/packages/@justaname.id/react/src/lib/constants/default-routes/index.ts
@@ -9,4 +9,4 @@ export const defaultRoutes = {
signinNonceRoute: '/api/signin/nonce',
signoutRoute: '/api/signout',
currentEnsRoute: '/api/current',
-} as const;
+};
diff --git a/packages/@justaname.id/react/src/lib/hooks/ebdc/index.ts b/packages/@justaname.id/react/src/lib/hooks/ebdc/index.ts
deleted file mode 100644
index c67dda55..00000000
--- a/packages/@justaname.id/react/src/lib/hooks/ebdc/index.ts
+++ /dev/null
@@ -1,3 +0,0 @@
-export * from './useAddEbdcPermission';
-export * from './useRevokeEbdcPermission';
-export * from './useIsEbdcEnabled';
\ No newline at end of file
diff --git a/packages/@justaname.id/react/src/lib/hooks/ebdc/useAddEbdcPermission.ts b/packages/@justaname.id/react/src/lib/hooks/ebdc/useAddEbdcPermission.ts
deleted file mode 100644
index 087a55fb..00000000
--- a/packages/@justaname.id/react/src/lib/hooks/ebdc/useAddEbdcPermission.ts
+++ /dev/null
@@ -1,62 +0,0 @@
-import { UseMutateFunction, useMutation } from '@tanstack/react-query';
-import { useJustaName } from '../../providers';
-import { AddEbdcPermissionResponse } from '@justaname.id/sdk';
-import { useSignMessage } from 'wagmi';
-import { useAccountSubnames, useMountedAccount } from '../account';
-
-export interface UseRequestAddEbdcPermission {
- addEbdcPermission: UseMutateFunction;
- isAddEbdcPermissionPending: boolean;
-}
-
-export interface AddEbdcPermissionRequest {
- subname: string
-}
-
-export const useAddEbdcPermission = ({
- ensDomain
- }: {
- ensDomain: string
-}): UseRequestAddEbdcPermission => {
- const { justaname } = useJustaName()
- const { signMessageAsync } = useSignMessage()
- const { address} = useMountedAccount()
- const { refetchAccountSubnames } = useAccountSubnames()
- const mutate = useMutation<
- AddEbdcPermissionResponse,
- Error,
- AddEbdcPermissionRequest
- >({
- mutationFn: async (
- params:AddEbdcPermissionRequest
- ) => {
- if (!address) {
- throw new Error('Wallet not connected')
- }
- const challengeResponse = await justaname.ebdc.requestAddEbdcPermissionChallenge({
- subname: params.subname,
- address: address,
- ensDomain,
- })
-
- const signature = await signMessageAsync({
- message: challengeResponse.challenge,
- account: address
- })
-
- const response = await justaname.ebdc.addEbdcPermission({
- message: challengeResponse.challenge,
- address: address,
- signature
- })
-
- refetchAccountSubnames()
- return response
- }
- })
-
- return {
- addEbdcPermission: mutate.mutate,
- isAddEbdcPermissionPending: mutate.isPending
- }
-}
\ No newline at end of file
diff --git a/packages/@justaname.id/react/src/lib/hooks/ebdc/useIsEbdcEnabled.ts b/packages/@justaname.id/react/src/lib/hooks/ebdc/useIsEbdcEnabled.ts
deleted file mode 100644
index a14882ae..00000000
--- a/packages/@justaname.id/react/src/lib/hooks/ebdc/useIsEbdcEnabled.ts
+++ /dev/null
@@ -1,41 +0,0 @@
-import { ChainId } from '@justaname.id/sdk';
-import { useQuery } from '@tanstack/react-query';
-import { useJustaName } from '../../providers';
-
-
-export const buildIsEbdcEnabledKey = (
- subname: string,
- ebdc: string,
- chainId: ChainId
-) => [
- 'IS_EBDC_ENABLED',
- subname,
- ebdc,
- chainId
-]
-
-export interface UseIsEbdcEnabledParams {
- subname: string;
- ebdc: string;
- chainId?: ChainId;
-}
-
-export const useIsEbdcEnabled = (params: UseIsEbdcEnabledParams) => {
- const { justaname, chainId} = useJustaName();
- const currentChainId = params.chainId || chainId;
- const query = useQuery({
- queryKey: buildIsEbdcEnabledKey(params.subname, params.ebdc,currentChainId),
- queryFn: async () => {
- return await justaname?.ebdc.checkIfEbdcIsEnabled({
- subname: params.subname,
- ebdc: params.ebdc,
- chainId: currentChainId
- })
- }
- })
-
- return {
- isEbdcEnabled: query.data,
- isEbdcEnabledPending: query.isPending
- }
-}
\ No newline at end of file
diff --git a/packages/@justaname.id/react/src/lib/hooks/index.ts b/packages/@justaname.id/react/src/lib/hooks/index.ts
index 89e95cc7..9cd7d734 100644
--- a/packages/@justaname.id/react/src/lib/hooks/index.ts
+++ b/packages/@justaname.id/react/src/lib/hooks/index.ts
@@ -5,4 +5,4 @@ export * from './signIn'
export * from './account'
export * from './subname';
export * from './records';
-export * from './ebdc';
\ No newline at end of file
+export * from './mApp';
\ No newline at end of file
diff --git a/packages/@justaname.id/react/src/lib/hooks/mApp/index.ts b/packages/@justaname.id/react/src/lib/hooks/mApp/index.ts
new file mode 100644
index 00000000..aaf3e7cb
--- /dev/null
+++ b/packages/@justaname.id/react/src/lib/hooks/mApp/index.ts
@@ -0,0 +1,3 @@
+export * from './useAddMAppPermission';
+export * from './useRevokeMAppPermission';
+export * from './useIsMAppEnabled';
\ No newline at end of file
diff --git a/packages/@justaname.id/react/src/lib/hooks/mApp/useAddMAppPermission.ts b/packages/@justaname.id/react/src/lib/hooks/mApp/useAddMAppPermission.ts
new file mode 100644
index 00000000..3d04a2d0
--- /dev/null
+++ b/packages/@justaname.id/react/src/lib/hooks/mApp/useAddMAppPermission.ts
@@ -0,0 +1,66 @@
+import { UseMutateAsyncFunction, useMutation } from '@tanstack/react-query';
+import { useJustaName } from '../../providers';
+import { AddMAppPermissionResponse, ChainId } from '@justaname.id/sdk';
+import { useSignMessage } from 'wagmi';
+import { useAccountSubnames, useMountedAccount } from '../account';
+
+export interface UseRequestAddMAppPermission {
+ addMAppPermission: UseMutateAsyncFunction;
+ isAddMAppPermissionPending: boolean;
+}
+
+export interface AddMAppPermissionRequest {
+ subname: string
+}
+
+export interface UseAddMAppPermissionParams {
+ mApp: string
+ chainId?: ChainId
+}
+
+
+export const useAddMAppPermission = (props : UseAddMAppPermissionParams): UseRequestAddMAppPermission => {
+ const { justaname, chainId } = useJustaName()
+ const { signMessageAsync } = useSignMessage()
+ const { address} = useMountedAccount()
+ const currentChainId = props.chainId || chainId
+ const { refetchAccountSubnames } = useAccountSubnames()
+ const mutate = useMutation<
+ AddMAppPermissionResponse,
+ Error,
+ AddMAppPermissionRequest
+ >({
+ mutationFn: async (
+ params:AddMAppPermissionRequest
+ ) => {
+ if (!address) {
+ throw new Error('Wallet not connected')
+ }
+ const challengeResponse = await justaname.mApps.requestAddMAppPermissionChallenge({
+ subname: params.subname,
+ address: address,
+ mApp: props.mApp,
+ chainId: currentChainId
+ })
+
+ const signature = await signMessageAsync({
+ message: challengeResponse.challenge,
+ account: address
+ })
+
+ const response = await justaname.mApps.addMAppPermission({
+ message: challengeResponse.challenge,
+ address: address,
+ signature,
+ })
+
+ refetchAccountSubnames()
+ return response
+ }
+ })
+
+ return {
+ addMAppPermission: mutate.mutateAsync,
+ isAddMAppPermissionPending: mutate.isPending
+ }
+}
\ No newline at end of file
diff --git a/packages/@justaname.id/react/src/lib/hooks/mApp/useIsMAppEnabled.ts b/packages/@justaname.id/react/src/lib/hooks/mApp/useIsMAppEnabled.ts
new file mode 100644
index 00000000..70292b5e
--- /dev/null
+++ b/packages/@justaname.id/react/src/lib/hooks/mApp/useIsMAppEnabled.ts
@@ -0,0 +1,49 @@
+import { ChainId } from '@justaname.id/sdk';
+import { useQuery } from '@tanstack/react-query';
+import { useJustaName } from '../../providers';
+
+
+export const buildIsMAppEnabledKey = (
+ subname: string,
+ mApp: string,
+ chainId: ChainId
+) => [
+ 'IS_EBDC_ENABLED',
+ subname,
+ mApp,
+ chainId
+]
+
+export interface UseIsMAppEnabledParams {
+ subname: string;
+ mApp: string;
+ chainId?: ChainId;
+}
+
+export interface UseIsMAppEnabledResult {
+ isMAppEnabled: boolean | undefined;
+ isMAppEnabledPending: boolean;
+ refetchIsMAppEnabled: () => void;
+}
+
+export const useIsMAppEnabled = (params: UseIsMAppEnabledParams): UseIsMAppEnabledResult => {
+ const { justaname, chainId} = useJustaName();
+ const currentChainId = params.chainId || chainId;
+ const query = useQuery({
+ queryKey: buildIsMAppEnabledKey(params.subname, params.mApp,currentChainId),
+ queryFn: async () => {
+ return await justaname?.mApps.checkIfMAppIsEnabled({
+ subname: params.subname,
+ mApp: params.mApp,
+ chainId: currentChainId
+ })
+ },
+ enabled: Boolean(params.subname) && Boolean(justaname) && params.subname.length > 0 && params.mApp.length > 0
+ })
+
+ return {
+ isMAppEnabled: query.data,
+ refetchIsMAppEnabled: query.refetch,
+ isMAppEnabledPending: query.isPending
+ }
+}
\ No newline at end of file
diff --git a/packages/@justaname.id/react/src/lib/hooks/ebdc/useRevokeEbdcPermission.ts b/packages/@justaname.id/react/src/lib/hooks/mApp/useRevokeMAppPermission.ts
similarity index 71%
rename from packages/@justaname.id/react/src/lib/hooks/ebdc/useRevokeEbdcPermission.ts
rename to packages/@justaname.id/react/src/lib/hooks/mApp/useRevokeMAppPermission.ts
index efc3efa6..68e21d94 100644
--- a/packages/@justaname.id/react/src/lib/hooks/ebdc/useRevokeEbdcPermission.ts
+++ b/packages/@justaname.id/react/src/lib/hooks/mApp/useRevokeMAppPermission.ts
@@ -1,11 +1,11 @@
import { UseMutateFunction, useMutation } from '@tanstack/react-query';
import { useJustaName } from '../../providers';
-import { RevokeEbdcPermissionResponse } from '@justaname.id/sdk';
+import { RevokeMAppPermissionResponse } from '@justaname.id/sdk';
import { useSignMessage } from 'wagmi';
import { useAccountSubnames, useMountedAccount } from '../account';
export interface UseRequestRevokeEbdcPermission {
- addEbdcPermission: UseMutateFunction;
+ addEbdcPermission: UseMutateFunction;
isRevokeEbdcPermissionPending: boolean;
}
@@ -13,17 +13,17 @@ export interface RevokeEbdcPermissionRequest {
subname: string
}
-export const useRevokeEbdcPermission = ({
- ensDomain
- }: {
- ensDomain: string
-}): UseRequestRevokeEbdcPermission => {
+export interface UseRevokeMAppPermissionParams {
+ mApp: string
+}
+
+export const useRevokeMAppPermission = ({ mApp }: UseRevokeMAppPermissionParams): UseRequestRevokeEbdcPermission => {
const { justaname } = useJustaName()
const { signMessageAsync } = useSignMessage()
const { address} = useMountedAccount()
const { refetchAccountSubnames } = useAccountSubnames()
const mutate = useMutation<
- RevokeEbdcPermissionResponse,
+ RevokeMAppPermissionResponse,
Error,
RevokeEbdcPermissionRequest
>({
@@ -33,10 +33,10 @@ export const useRevokeEbdcPermission = ({
if (!address) {
throw new Error('Wallet not connected')
}
- const challengeResponse = await justaname.ebdc.requestRevokeEbdcFieldChallenge({
+ const challengeResponse = await justaname.mApps.requestRevokeMAppPermissionChallenge({
subname: params.subname,
address: address,
- ensDomain,
+ mApp: mApp
})
const signature = await signMessageAsync({
@@ -44,7 +44,7 @@ export const useRevokeEbdcPermission = ({
account: address
})
- const response = await justaname.ebdc.revokeEbdcPermission({
+ const response = await justaname.mApps.revokeMAppPermission({
message: challengeResponse.challenge,
address: address,
signature
diff --git a/packages/@justaname.id/react/src/lib/providers/JustaNameProvider.tsx b/packages/@justaname.id/react/src/lib/providers/JustaNameProvider.tsx
index bd6e0a6c..60ea4bb7 100644
--- a/packages/@justaname.id/react/src/lib/providers/JustaNameProvider.tsx
+++ b/packages/@justaname.id/react/src/lib/providers/JustaNameProvider.tsx
@@ -133,4 +133,5 @@ export const useJustaName = (): JustaNameContextProps => {
throw new Error('useJustaName must be used within a JustaNameProvider');
}
return context;
-}
\ No newline at end of file
+}
+
diff --git a/packages/@justaname.id/sdk/.env.example b/packages/@justaname.id/sdk/.env.example
index cf971eaa..a7820319 100644
--- a/packages/@justaname.id/sdk/.env.example
+++ b/packages/@justaname.id/sdk/.env.example
@@ -1,5 +1,7 @@
-JUSTANAME_ENVIRONMENT=development # development: test on staging
-JUSTANAME_TEST_API_KEY=
-PRIVATE_KEY=
-PROVIDER_URL=
-VALID_SUBNAME= # resolvable subname
\ No newline at end of file
+SDK_JUSTANAME_ENVIRONMENT=development # development: test on staging
+SDK_JUSTANAME_TEST_API_KEY=
+SDK_PROVIDER_URL=
+SDK_MAPP_PRIVATE_KEY=
+SDK_ENS_DOMAIN=
+SDK_MAPP=
+
diff --git a/packages/@justaname.id/sdk/src/lib/api/routes/ebdc.ts b/packages/@justaname.id/sdk/src/lib/api/routes/ebdc.ts
deleted file mode 100644
index b377d49a..00000000
--- a/packages/@justaname.id/sdk/src/lib/api/routes/ebdc.ts
+++ /dev/null
@@ -1,22 +0,0 @@
-import { GLOBAL_PREFIX} from './prefix';
-
-/**
- * Prefix for all EBDC routes
- */
-const EBDC_ROUTE = GLOBAL_PREFIX + '/ens/v1/ebdc';
-
-/**
- * Routes for EBDC Add Permission
- */
-export const EBDC_ADD_PERMISSION_ROUTE = EBDC_ROUTE + '/permission/add';
-
-/**
- * Routes for EBDC Append Field
- */
-export const EBDC_APPEND_FIELD_ROUTE = EBDC_ROUTE + '/field/append';
-
-
-/**
- * Routes for EBDC Revoke Permission
- */
-export const EBDC_REVOKE_PERMISSION_ROUTE = EBDC_ROUTE + '/permission/revoke';
\ No newline at end of file
diff --git a/packages/@justaname.id/sdk/src/lib/api/routes/index.ts b/packages/@justaname.id/sdk/src/lib/api/routes/index.ts
index 3b126a13..fa829421 100644
--- a/packages/@justaname.id/sdk/src/lib/api/routes/index.ts
+++ b/packages/@justaname.id/sdk/src/lib/api/routes/index.ts
@@ -18,27 +18,27 @@ import {
SubnameRevokeRoute,
SubnameSearchRoute,
SubnameUpdateRoute,
- RequestAddEbdcPermissionChallengeRoute,
- RequestAppendEbdcFieldChallengeRoute,
- RequestRevokeEbdcFieldChallengeRoute,
- AddEbdcPermissionRoute,
- AppendEbdcFieldRoute,
- RevokeEbdcPermissionRoute
+ RequestAddMAppPermissionChallengeRoute,
+ RequestAppendMAppFieldChallengeRoute,
+ RequestRevokeMAppFieldChallengeRoute,
+ AddMAppPermissionRoute,
+ AppendMAppFieldRoute,
+ RevokeMAppPermissionRoute
} from '../../types';
import { HEALTH_CHECK_ROUTE } from './api-key';
import { OFFCHAIN_RESOLVERS_ROUTE } from './offchain-resolver';
import {
SIWE_REQUEST_CHALLENGE_ROUTE,
SIWE_VERIFY_MESSAGE_ROUTE,
- SIWE_EBDC_ADD_PERMISSION_ROUTE,
- SIWE_EBDC_APPEND_FIELD_ROUTE,
- SIWE_EBDC_REVOKE_PERMISSION_ROUTE
+ SIWE_MAPP_ADD_PERMISSION_ROUTE,
+ SIWE_MAPP_APPEND_FIELD_ROUTE,
+ SIWE_MAPP_REVOKE_PERMISSION_ROUTE
} from './siwe';
import {
- EBDC_ADD_PERMISSION_ROUTE,
- EBDC_APPEND_FIELD_ROUTE,
- EBDC_REVOKE_PERMISSION_ROUTE
-} from './ebdc'
+ MAPP_ADD_PERMISSION_ROUTE,
+ MAPP_APPEND_FIELD_ROUTE,
+ MAPP_REVOKE_PERMISSION_ROUTE
+} from './mapp'
import {
ACCEPT_SUBNAME_ROUTE,
ADD_SUBNAME_ROUTE,
@@ -61,12 +61,12 @@ export const Routes = {
HEALTH_CHECK_ROUTE,
SIWE_VERIFY_MESSAGE_ROUTE,
SIWE_REQUEST_CHALLENGE_ROUTE,
- SIWE_EBDC_ADD_PERMISSION_ROUTE,
- SIWE_EBDC_APPEND_FIELD_ROUTE,
- SIWE_EBDC_REVOKE_PERMISSION_ROUTE,
- EBDC_ADD_PERMISSION_ROUTE,
- EBDC_APPEND_FIELD_ROUTE,
- EBDC_REVOKE_PERMISSION_ROUTE,
+ SIWE_MAPP_ADD_PERMISSION_ROUTE,
+ SIWE_MAPP_APPEND_FIELD_ROUTE,
+ SIWE_MAPP_REVOKE_PERMISSION_ROUTE,
+ MAPP_ADD_PERMISSION_ROUTE,
+ MAPP_APPEND_FIELD_ROUTE,
+ MAPP_REVOKE_PERMISSION_ROUTE,
ACCEPT_SUBNAME_ROUTE,
RESERVE_SUBNAME_ROUTE,
ADD_SUBNAME_ROUTE,
@@ -95,12 +95,12 @@ export interface ROUTES extends IROUTES {
HEALTH_CHECK_ROUTE: ApiKeyRoute;
SIWE_VERIFY_MESSAGE_ROUTE: VerifyMessageRoute;
SIWE_REQUEST_CHALLENGE_ROUTE: RequestChallengeRoute;
- SIWE_EBDC_ADD_PERMISSION_ROUTE: RequestAddEbdcPermissionChallengeRoute;
- SIWE_EBDC_APPEND_FIELD_ROUTE: RequestAppendEbdcFieldChallengeRoute;
- SIWE_EBDC_REVOKE_PERMISSION_ROUTE: RequestRevokeEbdcFieldChallengeRoute;
- EBDC_ADD_PERMISSION_ROUTE: AddEbdcPermissionRoute;
- EBDC_APPEND_FIELD_ROUTE: AppendEbdcFieldRoute;
- EBDC_REVOKE_PERMISSION_ROUTE: RevokeEbdcPermissionRoute;
+ SIWE_MAPP_ADD_PERMISSION_ROUTE: RequestAddMAppPermissionChallengeRoute;
+ SIWE_MAPP_APPEND_FIELD_ROUTE: RequestAppendMAppFieldChallengeRoute;
+ SIWE_MAPP_REVOKE_PERMISSION_ROUTE: RequestRevokeMAppFieldChallengeRoute;
+ MAPP_ADD_PERMISSION_ROUTE: AddMAppPermissionRoute;
+ MAPP_APPEND_FIELD_ROUTE: AppendMAppFieldRoute;
+ MAPP_REVOKE_PERMISSION_ROUTE: RevokeMAppPermissionRoute;
ACCEPT_SUBNAME_ROUTE: SubnameAcceptRoute;
RESERVE_SUBNAME_ROUTE: SubnameReserveRoute;
ADD_SUBNAME_ROUTE: SubnameAddRoute;
diff --git a/packages/@justaname.id/sdk/src/lib/api/routes/mapp.ts b/packages/@justaname.id/sdk/src/lib/api/routes/mapp.ts
new file mode 100644
index 00000000..b5f37936
--- /dev/null
+++ b/packages/@justaname.id/sdk/src/lib/api/routes/mapp.ts
@@ -0,0 +1,22 @@
+import { GLOBAL_PREFIX} from './prefix';
+
+/**
+ * Prefix for all MAPP routes
+ */
+const MAPP_ROUTE = GLOBAL_PREFIX + '/ens/v1/mapp';
+
+/**
+ * Routes for MAPP Add Permission
+ */
+export const MAPP_ADD_PERMISSION_ROUTE = MAPP_ROUTE + '/permission/add';
+
+/**
+ * Routes for MAPP Append Field
+ */
+export const MAPP_APPEND_FIELD_ROUTE = MAPP_ROUTE + '/field/append';
+
+
+/**
+ * Routes for MAPP Revoke Permission
+ */
+export const MAPP_REVOKE_PERMISSION_ROUTE = MAPP_ROUTE + '/permission/revoke';
\ No newline at end of file
diff --git a/packages/@justaname.id/sdk/src/lib/api/routes/siwe.ts b/packages/@justaname.id/sdk/src/lib/api/routes/siwe.ts
index 0591f963..3c233bcb 100644
--- a/packages/@justaname.id/sdk/src/lib/api/routes/siwe.ts
+++ b/packages/@justaname.id/sdk/src/lib/api/routes/siwe.ts
@@ -16,16 +16,16 @@ export const SIWE_REQUEST_CHALLENGE_ROUTE = SIWE_BASE_ROUTE + '/request-challeng
export const SIWE_VERIFY_MESSAGE_ROUTE = SIWE_BASE_ROUTE + '/verify-message';
/**
- * Routes for SIWE Request Challenge to Add EBDC Permission
+ * Routes for SIWE Request Challenge to Add MAPP Permission
*/
-export const SIWE_EBDC_ADD_PERMISSION_ROUTE = SIWE_BASE_ROUTE + '/ebdc/add-permission';
+export const SIWE_MAPP_ADD_PERMISSION_ROUTE = SIWE_BASE_ROUTE + '/mapp/add-permission';
/**
* Routes for SIWE Request Challenge to Append Field
*/
-export const SIWE_EBDC_APPEND_FIELD_ROUTE = SIWE_BASE_ROUTE + '/ebdc/append-field';
+export const SIWE_MAPP_APPEND_FIELD_ROUTE = SIWE_BASE_ROUTE + '/mapp/append-field';
/**
* Routes for SIWE Request Challenge to Revoke Permission
*/
-export const SIWE_EBDC_REVOKE_PERMISSION_ROUTE = SIWE_BASE_ROUTE + '/ebdc/revoke-permission';
\ No newline at end of file
+export const SIWE_MAPP_REVOKE_PERMISSION_ROUTE = SIWE_BASE_ROUTE + '/mapp/revoke-permission';
\ No newline at end of file
diff --git a/packages/@justaname.id/sdk/src/lib/features/ebdc/index.ts b/packages/@justaname.id/sdk/src/lib/features/ebdc/index.ts
deleted file mode 100644
index 077569cf..00000000
--- a/packages/@justaname.id/sdk/src/lib/features/ebdc/index.ts
+++ /dev/null
@@ -1,111 +0,0 @@
-import {
- SiweConfig,
- RequestAddEbdcPermissionChallengeParams,
- RequestAddEbdcPermissionChallengeResponse,
- RequestAppendEbdcFieldChallengeParams,
- RequestAppendEbdcFieldChallengeResponse,
- RequestRevokeEbdcFieldChallengeParams,
- RequestRevokeEbdcFieldChallengeResponse,
- AddEbdcPermissionParams,
- AppendEbdcFieldParams,
- RevokeEbdcPermissionParams,
- SIWEHeaders, AppendEbdcFieldResponse, AddEbdcPermissionResponse, RevokeEbdcPermissionResponse, ChainId, Ebdc
-} from '../../types';
-import { restCall } from '../../api/rest';
-import { Subnames } from '../subnames';
-
-export class EBDC {
- siweConfig: SiweConfig;
- ensDomain: string;
- subnames: Subnames;
-
- constructor(
- ensDomain: string,
- config: SiweConfig,
- subnames: Subnames
- ) {
- this.siweConfig = config;
- this.ensDomain = ensDomain;
- this.subnames = subnames;
- }
-
- async checkIfEbdcIsEnabled({
- ebdc,
- subname,
- chainId,
- }: {
- ebdc: string;
- subname: string;
- chainId?: ChainId;
- }): Promise {
- const records = await this.subnames.getRecordsByFullName({
- fullName: subname,
- chainId
- })
-
- if (!records) {
- return false;
- }
-
- const ebdcField = records.texts.find((text) => text.key === 'ebdc')
-
- if (!ebdcField) {
- return false;
- }
-
- const ebdcFieldValue = JSON.parse(ebdcField.value) as Ebdc
-
- if (!ebdcFieldValue) {
- return false;
- }
-
- return ebdcFieldValue.ebdcs.includes(ebdc)
- }
-
- requestAddEbdcPermissionChallenge (params: RequestAddEbdcPermissionChallengeParams): Promise {
- return restCall('SIWE_EBDC_ADD_PERMISSION_ROUTE','POST', {
- ...this.siweConfig,
- ttl: 120000,
- ...params
- })
- }
-
- requestAppendEbdcFieldChallenge (params: RequestAppendEbdcFieldChallengeParams): Promise {
- return restCall('SIWE_EBDC_APPEND_FIELD_ROUTE','POST', {
- ...this.siweConfig,
- ttl: 120000,
- ...params
- })
- }
-
- requestRevokeEbdcFieldChallenge (params: RequestRevokeEbdcFieldChallengeParams): Promise {
- return restCall('SIWE_EBDC_REVOKE_PERMISSION_ROUTE','POST', {
- ...this.siweConfig,
- ttl: 120000,
- ...params
- })
- }
-
- addEbdcPermission(params: AddEbdcPermissionParams): Promise {
- return restCall('EBDC_ADD_PERMISSION_ROUTE','POST', {
- ...params
- })
- }
-
- appendEbdcField(
- params: AppendEbdcFieldParams,
- headers: SIWEHeaders
- ): Promise {
- return restCall('EBDC_APPEND_FIELD_ROUTE','POST', {
- ...params
- }, {
- ...headers
- })
- }
-
- revokeEbdcPermission(params: RevokeEbdcPermissionParams): Promise {
- return restCall('EBDC_REVOKE_PERMISSION_ROUTE','POST', {
- ...params
- })
- }
-}
diff --git a/packages/@justaname.id/sdk/src/lib/features/index.ts b/packages/@justaname.id/sdk/src/lib/features/index.ts
index f4bd7df0..575a50ed 100644
--- a/packages/@justaname.id/sdk/src/lib/features/index.ts
+++ b/packages/@justaname.id/sdk/src/lib/features/index.ts
@@ -2,4 +2,4 @@ export * from './subname-challenge';
export * from './subnames';
export * from './offchain-resolvers';
export * from './sign-in';
-export * from './ebdc';
\ No newline at end of file
+export * from './mApp';
\ No newline at end of file
diff --git a/packages/@justaname.id/sdk/src/lib/features/mApp/index.ts b/packages/@justaname.id/sdk/src/lib/features/mApp/index.ts
new file mode 100644
index 00000000..1f74bcc5
--- /dev/null
+++ b/packages/@justaname.id/sdk/src/lib/features/mApp/index.ts
@@ -0,0 +1,109 @@
+import {
+ SiweConfig,
+ RequestAddMAppPermissionChallengeParams,
+ RequestAddMAppPermissionChallengeResponse,
+ RequestAppendMAppFieldChallengeParams,
+ RequestAppendMAppFieldChallengeResponse,
+ RequestRevokeMAppPermissionChallengeParams,
+ RequestRevokeMAppPermissionChallengeResponse,
+ AddMAppPermissionParams,
+ AppendMAppFieldParams,
+ RevokeMAppPermissionParams,
+ SIWEHeaders, AppendMAppFieldResponse, AddMAppPermissionResponse, RevokeMAppPermissionResponse, ChainId, MApp
+} from '../../types';
+import { restCall } from '../../api/rest';
+import { Subnames } from '../subnames';
+
+export class MApps {
+ siweConfig: SiweConfig;
+ subnames: Subnames;
+
+ constructor(
+ config: SiweConfig,
+ subnames: Subnames
+ ) {
+ this.siweConfig = config;
+ this.subnames = subnames;
+ }
+
+ async checkIfMAppIsEnabled({
+ mApp,
+ subname,
+ chainId,
+ }: {
+ mApp: string;
+ subname: string;
+ chainId?: ChainId;
+ }): Promise {
+ const records = await this.subnames.getRecordsByFullName({
+ fullName: subname,
+ chainId
+ })
+
+ if (!records) {
+ return false;
+ }
+
+ const mAppField = records.texts.find((text) => text.key === 'mApps')
+
+ if (!mAppField) {
+ return false;
+ }
+
+ const mAppFieldValue = JSON.parse(mAppField.value) as MApp
+
+ if (!mAppFieldValue) {
+ return false;
+ }
+
+ return mAppFieldValue.mApps.includes(mApp)
+ }
+
+ requestAddMAppPermissionChallenge (params: RequestAddMAppPermissionChallengeParams): Promise {
+ return restCall('SIWE_MAPP_ADD_PERMISSION_ROUTE','POST', {
+ ...this.siweConfig,
+ ttl: 120000,
+
+ ...params
+ })
+ }
+
+ requestAppendMAppFieldChallenge (params: RequestAppendMAppFieldChallengeParams): Promise {
+ return restCall('SIWE_MAPP_APPEND_FIELD_ROUTE','POST', {
+ ...this.siweConfig,
+ ttl: 120000,
+ ...params
+ })
+ }
+
+ requestRevokeMAppPermissionChallenge (params: RequestRevokeMAppPermissionChallengeParams): Promise {
+ return restCall('SIWE_MAPP_REVOKE_PERMISSION_ROUTE','POST', {
+ ...this.siweConfig,
+ ttl: 120000,
+ ...params
+ })
+ }
+
+ addMAppPermission(params: AddMAppPermissionParams): Promise {
+ return restCall('MAPP_ADD_PERMISSION_ROUTE','POST', {
+ ...params
+ })
+ }
+
+ appendMAppField(
+ params: AppendMAppFieldParams,
+ headers: SIWEHeaders
+ ): Promise {
+ return restCall('MAPP_APPEND_FIELD_ROUTE','POST', {
+ ...params
+ }, {
+ ...headers
+ })
+ }
+
+ revokeMAppPermission(params: RevokeMAppPermissionParams): Promise {
+ return restCall('MAPP_REVOKE_PERMISSION_ROUTE','POST', {
+ ...params
+ })
+ }
+}
diff --git a/packages/@justaname.id/sdk/src/lib/justaname/index.ts b/packages/@justaname.id/sdk/src/lib/justaname/index.ts
index 7fed613d..9bb4e941 100644
--- a/packages/@justaname.id/sdk/src/lib/justaname/index.ts
+++ b/packages/@justaname.id/sdk/src/lib/justaname/index.ts
@@ -1,5 +1,5 @@
import { JustaNameConfig } from '../types';
-import { OffchainResolvers, SignIn, SubnameChallenge, Subnames, EBDC } from '../features';
+import { OffchainResolvers, SignIn, SubnameChallenge, Subnames, MApps } from '../features';
import { InvalidConfigurationException } from '../errors/InvalidConfiguration.exception';
/**
@@ -55,25 +55,25 @@ export class JustaName {
signIn: SignIn;
/**
- * The EBDC feature.
+ * The MApps feature.
* @public
- * @type {EBDC}
+ * @type {MApps}
* @memberof JustaName
*/
- ebdc: EBDC;
+ mApps: MApps;
constructor(
siwe: SubnameChallenge,
subnames: Subnames,
offchainResolvers: OffchainResolvers,
signIn: SignIn,
- ebdc: EBDC
+ mApps: MApps
) {
this.siwe = siwe;
this.subnames = subnames;
this.offchainResolvers = offchainResolvers;
this.signIn = signIn;
- this.ebdc = ebdc;
+ this.mApps = mApps;
}
/**
@@ -109,8 +109,7 @@ export class JustaName {
offchainResolvers
);
- const ebdc = new EBDC(
- configuration.ensDomain,
+ const mApps = new MApps(
configuration.config,
subnames
);
@@ -120,7 +119,7 @@ export class JustaName {
subnames,
offchainResolvers,
signIn,
- ebdc
+ mApps
);
}
diff --git a/packages/@justaname.id/sdk/src/lib/types/ebdc/ebdc.ts b/packages/@justaname.id/sdk/src/lib/types/ebdc/ebdc.ts
deleted file mode 100644
index 249aa1a4..00000000
--- a/packages/@justaname.id/sdk/src/lib/types/ebdc/ebdc.ts
+++ /dev/null
@@ -1,3 +0,0 @@
-export interface Ebdc {
- ebdcs: string[]
-}
\ No newline at end of file
diff --git a/packages/@justaname.id/sdk/src/lib/types/ebdc/index.ts b/packages/@justaname.id/sdk/src/lib/types/ebdc/index.ts
deleted file mode 100644
index d0e706d9..00000000
--- a/packages/@justaname.id/sdk/src/lib/types/ebdc/index.ts
+++ /dev/null
@@ -1,4 +0,0 @@
-export * from './add-ebdc-permission'
-export * from './append-ebdc-field'
-export * from './revoke-ebdc-permission'
-export * from './ebdc'
\ No newline at end of file
diff --git a/packages/@justaname.id/sdk/src/lib/types/index.ts b/packages/@justaname.id/sdk/src/lib/types/index.ts
index bbc35d89..5f97a83c 100644
--- a/packages/@justaname.id/sdk/src/lib/types/index.ts
+++ b/packages/@justaname.id/sdk/src/lib/types/index.ts
@@ -6,4 +6,4 @@ export * from './justaname';
export * from './offchain-resolver';
export * from './siwe';
export * from './subnames';
-export * from './ebdc';
\ No newline at end of file
+export * from './mapp';
\ No newline at end of file
diff --git a/packages/@justaname.id/sdk/src/lib/types/ebdc/add-ebdc-permission.ts b/packages/@justaname.id/sdk/src/lib/types/mapp/add-mApp-permission.ts
similarity index 85%
rename from packages/@justaname.id/sdk/src/lib/types/ebdc/add-ebdc-permission.ts
rename to packages/@justaname.id/sdk/src/lib/types/mapp/add-mApp-permission.ts
index 67e8b9db..9191a9f4 100644
--- a/packages/@justaname.id/sdk/src/lib/types/ebdc/add-ebdc-permission.ts
+++ b/packages/@justaname.id/sdk/src/lib/types/mapp/add-mApp-permission.ts
@@ -58,20 +58,20 @@ interface Metadata {
/**
* Outlines the response received after successfully updating a subname.
*
- * @interface AddEbdcPermissionResponse
+ * @interface AddMAppPermissionResponse
* @extends IResponse
* @public
* @property {string} id - The unique identifier of the update operation.
* @property {Metadata} data - The updated metadata associated with the subname.
*/
-export interface AddEbdcPermissionResponse extends IResponse{
+export interface AddMAppPermissionResponse extends IResponse{
id: string;
data: Metadata;
}
-export interface AddEbdcPermissionRequest extends IRequest {
+export interface AddMAppPermissionRequest extends IRequest {
/**
* Represents the ethereum address to be verified.
* @type {string}
@@ -92,10 +92,10 @@ export interface AddEbdcPermissionRequest extends IRequest {
message: string;
}
-export interface AddEbdcPermissionRoute extends IRoute {
- request: AddEbdcPermissionRequest;
- response: AddEbdcPermissionResponse;
+export interface AddMAppPermissionRoute extends IRoute {
+ request: AddMAppPermissionRequest;
+ response: AddMAppPermissionResponse;
headers: NonNullable;
}
-export interface AddEbdcPermissionParams extends AddEbdcPermissionRequest {}
\ No newline at end of file
+export interface AddMAppPermissionParams extends AddMAppPermissionRequest {}
\ No newline at end of file
diff --git a/packages/@justaname.id/sdk/src/lib/types/ebdc/append-ebdc-field.ts b/packages/@justaname.id/sdk/src/lib/types/mapp/append-mApp-field.ts
similarity index 82%
rename from packages/@justaname.id/sdk/src/lib/types/ebdc/append-ebdc-field.ts
rename to packages/@justaname.id/sdk/src/lib/types/mapp/append-mApp-field.ts
index 1a782cc9..0e6574ed 100644
--- a/packages/@justaname.id/sdk/src/lib/types/ebdc/append-ebdc-field.ts
+++ b/packages/@justaname.id/sdk/src/lib/types/mapp/append-mApp-field.ts
@@ -59,33 +59,33 @@ interface Metadata {
/**
* Outlines the response received after successfully updating a subname.
*
- * @interface AppendEbdcFieldResponse
+ * @interface AppendMAppFieldResponse
* @extends IResponse
* @public
* @property {string} id - The unique identifier of the update operation.
* @property {Metadata} data - The updated metadata associated with the subname.
*/
-export interface AppendEbdcFieldResponse extends IResponse{
+export interface AppendMAppFieldResponse extends IResponse{
id: string;
data: Metadata;
}
-export interface AppendEbdcFieldsRequest {
+export interface AppendMAppFieldsRequest {
key: string;
value: string;
}
-export interface AppendEbdcFieldRequest extends IRequest{
+export interface AppendMAppFieldRequest extends IRequest{
subname: string;
- fields: AppendEbdcFieldsRequest[];
+ fields: AppendMAppFieldsRequest[];
}
-export interface AppendEbdcFieldRoute extends IRoute {
- request: AppendEbdcFieldRequest;
- response: AppendEbdcFieldResponse;
+export interface AppendMAppFieldRoute extends IRoute {
+ request: AppendMAppFieldRequest;
+ response: AppendMAppFieldResponse;
headers: SIWEHeaders
}
-export interface AppendEbdcFieldParams extends AppendEbdcFieldRequest {}
\ No newline at end of file
+export interface AppendMAppFieldParams extends AppendMAppFieldRequest {}
\ No newline at end of file
diff --git a/packages/@justaname.id/sdk/src/lib/types/mapp/index.ts b/packages/@justaname.id/sdk/src/lib/types/mapp/index.ts
new file mode 100644
index 00000000..c90cffbf
--- /dev/null
+++ b/packages/@justaname.id/sdk/src/lib/types/mapp/index.ts
@@ -0,0 +1,4 @@
+export * from './add-mApp-permission'
+export * from './append-mApp-field'
+export * from './revoke-mApp-permission'
+export * from './mApp'
\ No newline at end of file
diff --git a/packages/@justaname.id/sdk/src/lib/types/mapp/mApp.ts b/packages/@justaname.id/sdk/src/lib/types/mapp/mApp.ts
new file mode 100644
index 00000000..e2ee2fbe
--- /dev/null
+++ b/packages/@justaname.id/sdk/src/lib/types/mapp/mApp.ts
@@ -0,0 +1,3 @@
+export interface MApp {
+ mApps: string[]
+}
\ No newline at end of file
diff --git a/packages/@justaname.id/sdk/src/lib/types/ebdc/revoke-ebdc-permission.ts b/packages/@justaname.id/sdk/src/lib/types/mapp/revoke-mApp-permission.ts
similarity index 87%
rename from packages/@justaname.id/sdk/src/lib/types/ebdc/revoke-ebdc-permission.ts
rename to packages/@justaname.id/sdk/src/lib/types/mapp/revoke-mApp-permission.ts
index c5fff002..efa3ff2c 100644
--- a/packages/@justaname.id/sdk/src/lib/types/ebdc/revoke-ebdc-permission.ts
+++ b/packages/@justaname.id/sdk/src/lib/types/mapp/revoke-mApp-permission.ts
@@ -64,14 +64,14 @@ interface Metadata {
* @property {string} id - The unique identifier of the update operation.
* @property {Metadata} data - The updated metadata associated with the subname.
*/
-export interface RevokeEbdcPermissionResponse extends IResponse{
+export interface RevokeMAppPermissionResponse extends IResponse{
id: string;
data: Metadata;
}
-export interface RevokeEbdcPermissionRequest extends IRequest {
+export interface RevokeMAppPermissionRequest extends IRequest {
/**
* Represents the ethereum address to be verified.
* @type {string}
@@ -92,10 +92,10 @@ export interface RevokeEbdcPermissionRequest extends IRequest {
message: string;
}
-export interface RevokeEbdcPermissionRoute extends IRoute {
- request: RevokeEbdcPermissionRequest;
- response: RevokeEbdcPermissionResponse;
+export interface RevokeMAppPermissionRoute extends IRoute {
+ request: RevokeMAppPermissionRequest;
+ response: RevokeMAppPermissionResponse;
headers: NonNullable;
}
-export interface RevokeEbdcPermissionParams extends RevokeEbdcPermissionRequest {}
\ No newline at end of file
+export interface RevokeMAppPermissionParams extends RevokeMAppPermissionRequest {}
\ No newline at end of file
diff --git a/packages/@justaname.id/sdk/src/lib/types/siwe/add-ebdc-permission-challenge.ts b/packages/@justaname.id/sdk/src/lib/types/siwe/add-mApp-permission-challenge.ts
similarity index 68%
rename from packages/@justaname.id/sdk/src/lib/types/siwe/add-ebdc-permission-challenge.ts
rename to packages/@justaname.id/sdk/src/lib/types/siwe/add-mApp-permission-challenge.ts
index c35a1d40..d5370b88 100644
--- a/packages/@justaname.id/sdk/src/lib/types/siwe/add-ebdc-permission-challenge.ts
+++ b/packages/@justaname.id/sdk/src/lib/types/siwe/add-mApp-permission-challenge.ts
@@ -2,11 +2,11 @@ import { ChainId, IRequest, IResponse, IRoute } from '../common';
/**
* Represents a request to challenge to add EBDC permission.
- * @interface RequestAddEbdcPermissionChallengeRequest
+ * @interface RequestAddMAppPermissionChallengeRequest
* @public
*/
-export interface RequestAddEbdcPermissionChallengeRequest extends IRequest {
+export interface RequestAddMAppPermissionChallengeRequest extends IRequest {
/**
* Represents the ENS domain
@@ -48,18 +48,18 @@ export interface RequestAddEbdcPermissionChallengeRequest extends IRequest {
subname: string
/**
- * Subname requesting the ABDC Permission
+ * Subname requesting the MApps Permission
* @type {string}
*/
- ensDomain: string
+ mApp: string
}
/**
* Represents the response to a request to challenge a specific address using SIWE.
- * @interface RequestAddEbdcPermissionChallengeResponse
+ * @interface RequestAddMAppPermissionChallengeResponse
* @public
*/
-export interface RequestAddEbdcPermissionChallengeResponse extends IResponse{
+export interface RequestAddMAppPermissionChallengeResponse extends IResponse{
/**
* Represents the challenge to be signed by the user.
* @type {string}
@@ -67,13 +67,13 @@ export interface RequestAddEbdcPermissionChallengeResponse extends IResponse{
challenge: string;
}
-export interface RequestAddEbdcPermissionChallengeRoute extends IRoute {
- request: RequestAddEbdcPermissionChallengeRequest;
- response: RequestAddEbdcPermissionChallengeResponse;
+export interface RequestAddMAppPermissionChallengeRoute extends IRoute {
+ request: RequestAddMAppPermissionChallengeRequest;
+ response: RequestAddMAppPermissionChallengeResponse;
headers: NonNullable;
}
-export interface RequestAddEbdcPermissionChallengeParams extends Omit {
+export interface RequestAddMAppPermissionChallengeParams extends Omit {
origin?: string,
domain?: string,
chainId?: ChainId,
diff --git a/packages/@justaname.id/sdk/src/lib/types/siwe/revoke-ebdc-permission-challenge.ts b/packages/@justaname.id/sdk/src/lib/types/siwe/append-mApp-field-challenge.ts
similarity index 68%
rename from packages/@justaname.id/sdk/src/lib/types/siwe/revoke-ebdc-permission-challenge.ts
rename to packages/@justaname.id/sdk/src/lib/types/siwe/append-mApp-field-challenge.ts
index 6ab3b1d3..c6e214d0 100644
--- a/packages/@justaname.id/sdk/src/lib/types/siwe/revoke-ebdc-permission-challenge.ts
+++ b/packages/@justaname.id/sdk/src/lib/types/siwe/append-mApp-field-challenge.ts
@@ -2,11 +2,11 @@ import { ChainId, IRequest, IResponse, IRoute } from '../common';
/**
* Represents a request to challenge to add EBDC permission.
- * @interface RequestRevokeEbdcFieldChallengeRequest
+ * @interface RequestAppendMAppFieldChallengeRequest
* @public
*/
-export interface RequestRevokeEbdcFieldChallengeRequest extends IRequest {
+export interface RequestAppendMAppFieldChallengeRequest extends IRequest {
/**
* Represents the ENS domain
@@ -48,18 +48,18 @@ export interface RequestRevokeEbdcFieldChallengeRequest extends IRequest {
subname: string
/**
- * Subname requesting the ABDC Permission
+ * Subname requesting the MApps Permission
* @type {string}
*/
- ensDomain: string
+ mApp: string
}
/**
* Represents the response to a request to challenge a specific address using SIWE.
- * @interface RequestRevokeEbdcFieldChallengeResponse
+ * @interface RequestAppendMAppFieldChallengeResponse
* @public
*/
-export interface RequestRevokeEbdcFieldChallengeResponse extends IResponse{
+export interface RequestAppendMAppFieldChallengeResponse extends IResponse{
/**
* Represents the challenge to be signed by the user.
* @type {string}
@@ -67,13 +67,13 @@ export interface RequestRevokeEbdcFieldChallengeResponse extends IResponse{
challenge: string;
}
-export interface RequestRevokeEbdcFieldChallengeRoute extends IRoute {
- request: RequestRevokeEbdcFieldChallengeRequest;
- response: RequestRevokeEbdcFieldChallengeResponse;
+export interface RequestAppendMAppFieldChallengeRoute extends IRoute {
+ request: RequestAppendMAppFieldChallengeRequest;
+ response: RequestAppendMAppFieldChallengeResponse;
headers: NonNullable;
}
-export interface RequestRevokeEbdcFieldChallengeParams extends Omit {
+export interface RequestAppendMAppFieldChallengeParams extends Omit {
origin?: string,
domain?: string,
chainId?: ChainId,
diff --git a/packages/@justaname.id/sdk/src/lib/types/siwe/index.ts b/packages/@justaname.id/sdk/src/lib/types/siwe/index.ts
index 38f32d65..065120fe 100644
--- a/packages/@justaname.id/sdk/src/lib/types/siwe/index.ts
+++ b/packages/@justaname.id/sdk/src/lib/types/siwe/index.ts
@@ -1,6 +1,6 @@
export * from './request-challenge'
export * from './verify-challenge'
-export * from './add-ebdc-permission-challenge'
-export * from './append-ebdc-field-challenge'
-export * from './revoke-ebdc-permission-challenge'
+export * from './add-mApp-permission-challenge'
+export * from './append-mApp-field-challenge'
+export * from './revoke-mApp-permission-challenge'
export * from './siwe-config'
\ No newline at end of file
diff --git a/packages/@justaname.id/sdk/src/lib/types/siwe/append-ebdc-field-challenge.ts b/packages/@justaname.id/sdk/src/lib/types/siwe/revoke-mApp-permission-challenge.ts
similarity index 65%
rename from packages/@justaname.id/sdk/src/lib/types/siwe/append-ebdc-field-challenge.ts
rename to packages/@justaname.id/sdk/src/lib/types/siwe/revoke-mApp-permission-challenge.ts
index 9481b6a3..659c249b 100644
--- a/packages/@justaname.id/sdk/src/lib/types/siwe/append-ebdc-field-challenge.ts
+++ b/packages/@justaname.id/sdk/src/lib/types/siwe/revoke-mApp-permission-challenge.ts
@@ -2,11 +2,11 @@ import { ChainId, IRequest, IResponse, IRoute } from '../common';
/**
* Represents a request to challenge to add EBDC permission.
- * @interface RequestAppendEbdcFieldChallengeRequest
+ * @interface RequestRevokeMAppFieldChallengeRequest
* @public
*/
-export interface RequestAppendEbdcFieldChallengeRequest extends IRequest {
+export interface RequestRevokeMAppFieldChallengeRequest extends IRequest {
/**
* Represents the ENS domain
@@ -48,18 +48,18 @@ export interface RequestAppendEbdcFieldChallengeRequest extends IRequest {
subname: string
/**
- * Subname requesting the ABDC Permission
+ * Subname requesting the MApps Permission
* @type {string}
*/
- ensDomain: string
+ mApp: string
}
/**
* Represents the response to a request to challenge a specific address using SIWE.
- * @interface RequestAppendEbdcFieldChallengeResponse
+ * @interface RequestRevokeMAppPermissionChallengeResponse
* @public
*/
-export interface RequestAppendEbdcFieldChallengeResponse extends IResponse{
+export interface RequestRevokeMAppPermissionChallengeResponse extends IResponse{
/**
* Represents the challenge to be signed by the user.
* @type {string}
@@ -67,13 +67,13 @@ export interface RequestAppendEbdcFieldChallengeResponse extends IResponse{
challenge: string;
}
-export interface RequestAppendEbdcFieldChallengeRoute extends IRoute {
- request: RequestAppendEbdcFieldChallengeRequest;
- response: RequestAppendEbdcFieldChallengeResponse;
+export interface RequestRevokeMAppFieldChallengeRoute extends IRoute {
+ request: RequestRevokeMAppFieldChallengeRequest;
+ response: RequestRevokeMAppPermissionChallengeResponse;
headers: NonNullable;
}
-export interface RequestAppendEbdcFieldChallengeParams extends Omit {
+export interface RequestRevokeMAppPermissionChallengeParams extends Omit {
origin?: string,
domain?: string,
chainId?: ChainId,
diff --git a/packages/@justaname.id/sdk/src/test/features/sign-in/sign-in.spec.ts b/packages/@justaname.id/sdk/src/test/features/sign-in/sign-in.spec.ts
index 9b713470..ad912e24 100644
--- a/packages/@justaname.id/sdk/src/test/features/sign-in/sign-in.spec.ts
+++ b/packages/@justaname.id/sdk/src/test/features/sign-in/sign-in.spec.ts
@@ -2,24 +2,31 @@ import { ethers } from 'ethers';
import dotenv from 'dotenv';
import SignIn from '../../../lib/features/sign-in';
import { OffchainResolvers } from '../../../lib/features';
+import { configureEnv } from '../../helpers/configureEnv';
+import { initializeJustaName } from '../../helpers/initializeJustaName';
+import { JustaName } from '../../../lib/justaname';
dotenv.config();
-const pk = process.env['PRIVATE_KEY'] as string;
-const signer = new ethers.Wallet(pk);
-const PROVIDER_URL = process.env['PROVIDER_URL'] as string;
+const PROVIDER_URL = process.env['SDK_PROVIDER_URL'] as string;
const DOMAIN = 'justaname.id';
const URI = 'https://' + DOMAIN;
-const ADDRESS = signer.address;
const CHAIN_ID = 11155111;
const VALID_TTL = 60 * 60 * 24 * 1000; // 1 day
-const VALID_ENS = process.env['VALID_ENS'] as string;
-
+const invalidSigner = new ethers.Wallet(ethers.Wallet.createRandom().privateKey);
+const ENS_DOMAIN = process.env['SDK_ENS_DOMAIN'] as string;
+const subnameSigner = ethers.Wallet.createRandom()
+const subnameToBeAdded = Math.random().toString(36).substring(7);
+const validApiKey = process.env['SDK_JUSTANAME_TEST_API_KEY'] as string;
describe('SignIn', () => {
let signIn: SignIn;
+ let justaname: JustaName;
+
+ beforeEach(async () => {
- beforeEach(() => {
+ await configureEnv();
+ justaname = initializeJustaName(validApiKey);
signIn = new SignIn({
origin: URI,
domain: DOMAIN,
@@ -30,6 +37,24 @@ describe('SignIn', () => {
);
});
+
+ it('should add a subname', async () => {
+ const challenge = await justaname.siwe.requestChallenge({
+ address: subnameSigner.address,
+ });
+
+ const signature = await subnameSigner.signMessage(challenge.challenge);
+ const response = await justaname.subnames.addSubname({
+ username: subnameToBeAdded
+ }, {
+ xMessage: challenge.challenge,
+ xAddress: subnameSigner.address,
+ xSignature: signature
+ })
+
+ expect(response).toBeDefined();
+ })
+
it('should create an instance', () => {
expect(signIn).toBeTruthy();
});
@@ -46,8 +71,8 @@ describe('SignIn', () => {
it('should request a challenge', async () => {
const response = signIn.requestSignIn({
- address: ADDRESS,
- ens: VALID_ENS,
+ address: subnameSigner.address,
+ ens: subnameToBeAdded + '.' + ENS_DOMAIN,
});
expect(response).toBeTruthy();
});
@@ -55,18 +80,18 @@ describe('SignIn', () => {
it('should verify a signature', async () => {
const message = signIn.requestSignIn({
- address: ADDRESS,
- ens: VALID_ENS,
+ address: subnameSigner.address,
+ ens: subnameToBeAdded + '.' + ENS_DOMAIN,
});
- const signature = await signer.signMessage(message);
+ const signature = await subnameSigner.signMessage(message);
const response = await signIn.signIn(message, signature);
expect(response.success).toBeTruthy();
},60000)
it('should fail to verify an invalid signature', async () => {
const message = signIn.requestSignIn({
- address: ADDRESS,
- ens: VALID_ENS,
+ address: invalidSigner.address,
+ ens: subnameToBeAdded + '.' + ENS_DOMAIN,
});
const signer2 = new ethers.Wallet(ethers.Wallet.createRandom().privateKey);
const signature = await signer2.signMessage(message);
@@ -82,11 +107,30 @@ describe('SignIn', () => {
it('should return true if JustaName resolver is Configured', async () => {
const message = signIn.requestSignIn({
- address: ADDRESS,
- ens: VALID_ENS,
+ address: subnameSigner.address,
+ ens: subnameToBeAdded + '.' + ENS_DOMAIN,
});
- const signature = await signer.signMessage(message);
+ const signature = await subnameSigner.signMessage(message);
const response = await signIn.signIn(message, signature);
expect(response.isJustaName).toBeTruthy();
},60000)
+
+ it('should revoke subname', async () => {
+ const challenge = await justaname.siwe.requestChallenge({
+ address: subnameSigner.address,
+ });
+
+ const signature = await subnameSigner.signMessage(challenge.challenge);
+
+ const response = await justaname.subnames.revokeSubname({
+ chainId: 11155111,
+ username: subnameToBeAdded
+ }, {
+ xAddress: subnameSigner.address,
+ xSignature: signature,
+ xMessage: challenge.challenge
+ })
+
+ expect(response).toBeDefined();
+ })
})
\ No newline at end of file
diff --git a/packages/@justaname.id/sdk/src/test/features/subname-challenge/subname-challenge.spec.ts b/packages/@justaname.id/sdk/src/test/features/subname-challenge/subname-challenge.spec.ts
index 18d2b9b3..c8f12cab 100644
--- a/packages/@justaname.id/sdk/src/test/features/subname-challenge/subname-challenge.spec.ts
+++ b/packages/@justaname.id/sdk/src/test/features/subname-challenge/subname-challenge.spec.ts
@@ -3,9 +3,7 @@ import rest from '../../../lib/api/rest';
import dotenv from 'dotenv';
import { ethers } from 'ethers';
dotenv.config();
-
-const pk = process.env['PRIVATE_KEY'] as string;
-const signer = new ethers.Wallet(pk);
+const signer = ethers.Wallet.createRandom();
describe('subnameChallenge', () => {
let subnameChallenge: SubnameChallenge;
@@ -25,7 +23,7 @@ challenge: '0x1234',
it('should be able to request a challenge', async () => {
const requestChallengeResponse = await subnameChallenge.requestChallenge({
- address: '0x59c44836630760F97b74b569B379ca94c37B93ca',
+ address: signer.address,
});
expect(requestChallengeResponse).toBeDefined();
})
diff --git a/packages/@justaname.id/sdk/src/test/features/subnames/subnames.spec.ts b/packages/@justaname.id/sdk/src/test/features/subnames/subnames.spec.ts
index f332a4e3..382f33de 100644
--- a/packages/@justaname.id/sdk/src/test/features/subnames/subnames.spec.ts
+++ b/packages/@justaname.id/sdk/src/test/features/subnames/subnames.spec.ts
@@ -5,7 +5,7 @@ import { ApiKeyRequiredException } from '../../../lib/errors/ApiKeyRequired.exce
const PROVIDER_URL = 'https://mainnet.infura.io/v3/your-infura-project-id';
const CHAIN_ID = 1;
const ENS_DOMAIN = 'justaname.eth';
-const validApiKey = process.env['JUSTANAME_TEST_API_KEY'] as string;
+const validApiKey = process.env['SDK_JUSTANAME_TEST_API_KEY'] as string;
describe('Subnames', () => {
diff --git a/packages/@justaname.id/sdk/src/test/helpers/initializeJustaName.ts b/packages/@justaname.id/sdk/src/test/helpers/initializeJustaName.ts
index 8723137c..9f5fe11a 100644
--- a/packages/@justaname.id/sdk/src/test/helpers/initializeJustaName.ts
+++ b/packages/@justaname.id/sdk/src/test/helpers/initializeJustaName.ts
@@ -2,10 +2,10 @@ import { JustaName } from '../../../src';
import dotenv from 'dotenv';
dotenv.config();
-const PROVIDER_URL = process.env['PROVIDER_URL'] as string;
+const PROVIDER_URL = process.env['SDK_PROVIDER_URL'] as string;
const DOMAIN = 'justaname.id';
const URI = 'https://' + DOMAIN;
-const ENS_DOMAIN = process.env['ENS_DOMAIN'] as string;
+const ENS_DOMAIN = process.env['SDK_ENS_DOMAIN'] as string;
const CHAIN_ID = 11155111;
const VALID_TTL = 60 * 60 * 24 * 1000; // 1 day
diff --git a/packages/@justaname.id/sdk/src/test/integration/justaname.spec.ts b/packages/@justaname.id/sdk/src/test/integration/justaname.spec.ts
index 5c36111b..debf932d 100644
--- a/packages/@justaname.id/sdk/src/test/integration/justaname.spec.ts
+++ b/packages/@justaname.id/sdk/src/test/integration/justaname.spec.ts
@@ -6,14 +6,16 @@ import dotenv from 'dotenv';
dotenv.config();
// const invalidApiKey = 'invalid-api-key';
-const validApiKey = process.env['JUSTANAME_TEST_API_KEY'] as string;
+const validApiKey = process.env['SDK_JUSTANAME_TEST_API_KEY'] as string;
jest.setTimeout(50000);
-const pk = process.env['PRIVATE_KEY'] as string;
-const signer = new ethers.Wallet(pk);
+const mAppPk = process.env['SDK_MAPP_PRIVATE_KEY'] as string;
+const mAppSigner = new ethers.Wallet(mAppPk);
const subnameSigner = ethers.Wallet.createRandom()
const subnameToBeAdded = Math.random().toString(36).substring(7);
-const ENS_DOMAIN = process.env['ENS_DOMAIN'] as string;
-
+const CHAIN_ID = 11155111;
+const ENS_DOMAIN = process.env['SDK_ENS_DOMAIN'] as string;
+const MAPP = process.env['SDK_MAPP'] as string;
+const MAPP_2 = MAPP.split('.')[0] + '2' + '.' + MAPP.split('.')[1];
describe('justaname', () => {
let justaname: JustaName;
@@ -32,7 +34,7 @@ describe('justaname', () => {
const challenge = await justaname.siwe.requestChallenge({
// 30mins
ttl:1800000,
- chainId: 1,
+ chainId: CHAIN_ID,
origin: 'http://localhost:3333',
address: '0x59c44836630760F97b74b569B379ca94c37B93ca',
domain: 'justaname.id',
@@ -42,7 +44,7 @@ describe('justaname', () => {
it('should sign in be 1 day', async () => {
const challenge = justaname.signIn.requestSignIn({
- address: signer.address,
+ address: subnameSigner.address,
ens: 'siwj.jaw.eth',
ttl: 1000 * 60 * 60 * 24
});
@@ -60,11 +62,13 @@ describe('justaname', () => {
it('should add a subname', async () => {
const challenge = await justaname.siwe.requestChallenge({
address: subnameSigner.address,
+ chainId: CHAIN_ID,
});
const signature = await subnameSigner.signMessage(challenge.challenge);
const response = await justaname.subnames.addSubname({
- username: subnameToBeAdded
+ username: subnameToBeAdded,
+ chainId: CHAIN_ID,
}, {
xMessage: challenge.challenge,
xAddress: subnameSigner.address,
@@ -74,6 +78,88 @@ describe('justaname', () => {
expect(response).toBeDefined();
})
+ it('should update a subname', async () => {
+ const challenge = await justaname.siwe.requestChallenge({
+ address: subnameSigner.address,
+ chainId: CHAIN_ID,
+ });
+
+ const signature = await subnameSigner.signMessage(challenge.challenge);
+
+ const response = await justaname.subnames.updateSubname({
+ contentHash: '',
+ username: subnameToBeAdded,
+ chainId: CHAIN_ID,
+ ensDomain: ENS_DOMAIN,
+ addresses: {},
+ text: {
+ test: 'test',
+ test2: 'test2',
+ }
+ }, {
+ xMessage: challenge.challenge,
+ xAddress: subnameSigner.address,
+ xSignature: signature
+ })
+
+ expect(response).toBeDefined();
+ })
+
+ it('mApps shouldn\'t be updated', async () => {
+
+ const challenge = await justaname.siwe.requestChallenge({
+ address: subnameSigner.address,
+ chainId: CHAIN_ID,
+ });
+
+ const signature = await subnameSigner.signMessage(challenge.challenge);
+
+ const response = await justaname.subnames.updateSubname({
+ contentHash: '',
+ username: subnameToBeAdded,
+ chainId: CHAIN_ID,
+ ensDomain: ENS_DOMAIN,
+ addresses: {},
+ text: {
+ 'mApps': 'shouldntBeUpdated',
+ [`test_${MAPP}`]: 'shouldBeOverrideWhenMAppPermissionIsAdded',
+ }
+ }, {
+ xMessage: challenge.challenge,
+ xAddress: subnameSigner.address,
+ xSignature: signature
+ })
+
+ const mApps = response.data.textRecords.find((text) => text.key === 'mApps')?.value;
+ expect(mApps).toBeUndefined();
+ })
+
+ it('should remove test if value is empty', async () => {
+ const challenge = await justaname.siwe.requestChallenge({
+ address: subnameSigner.address,
+ chainId: CHAIN_ID,
+ });
+
+ const signature = await subnameSigner.signMessage(challenge.challenge);
+
+ const response = await justaname.subnames.updateSubname({
+ contentHash: '',
+ username: subnameToBeAdded,
+ chainId: CHAIN_ID,
+ ensDomain: ENS_DOMAIN,
+ addresses: {},
+ text: {
+ test: '',
+ }
+ }, {
+ xMessage: challenge.challenge,
+ xAddress: subnameSigner.address,
+ xSignature: signature
+ })
+
+ expect(response.data.textRecords.find((text) => text.key === 'test')).toBeUndefined();
+ expect(response).toBeDefined();
+ })
it('should verify a challenge', async () => {
const challenge = justaname.signIn.requestSignIn({
@@ -89,24 +175,44 @@ describe('justaname', () => {
})
- it('shouldn\'t have ebdc enabled', async () => {
- const subname = await justaname.ebdc.checkIfEbdcIsEnabled({
+ it('shouldn\'t have mApps enabled', async () => {
+ const subname = await justaname.mApps.checkIfMAppIsEnabled({
subname: subnameToBeAdded + '.' + ENS_DOMAIN,
- ebdc: ENS_DOMAIN
+ mApp: MAPP,
+ chainId: CHAIN_ID
})
expect(subname).toBeFalsy();
})
- it('should add ebdc permission', async () => {
- const challenge = await justaname.ebdc.requestAddEbdcPermissionChallenge({
+ it('should add mApps permission', async () => {
+ const challenge = await justaname.mApps.requestAddMAppPermissionChallenge({
+ address: subnameSigner.address,
+ subname: subnameToBeAdded + '.' + ENS_DOMAIN,
+ mApp: MAPP,
+ chainId: CHAIN_ID
+ });
+
+ const signature = await subnameSigner.signMessage(challenge.challenge);
+ const response = await justaname.mApps.addMAppPermission({
+ address: subnameSigner.address,
+ signature,
+ message: challenge.challenge,
+ })
+
+ expect(response).toBeDefined();
+ })
+
+ it('should add mApps2 permission', async () => {
+ const challenge = await justaname.mApps.requestAddMAppPermissionChallenge({
address: subnameSigner.address,
subname: subnameToBeAdded + '.' + ENS_DOMAIN,
- ensDomain: ENS_DOMAIN
+ mApp: MAPP_2,
+ chainId: CHAIN_ID
});
const signature = await subnameSigner.signMessage(challenge.challenge);
- const response = await justaname.ebdc.addEbdcPermission({
+ const response = await justaname.mApps.addMAppPermission({
address: subnameSigner.address,
signature,
message: challenge.challenge,
@@ -115,32 +221,49 @@ describe('justaname', () => {
expect(response).toBeDefined();
})
- it('shouldn\'t have ebdc enabled', async () => {
- const subname = await justaname.ebdc.checkIfEbdcIsEnabled({
+ it('should have removed test_mApps', async () => {
+ const subname = await justaname.subnames.getRecordsByFullName({
+ fullName: subnameToBeAdded + '.' + ENS_DOMAIN,
+ chainId: CHAIN_ID
+ })
+
+ const testMApps = subname.texts.find((text) => text.key === `test_${MAPP}`)?.value;
+
+ expect(testMApps).toBeUndefined();
+ })
+
+ it('should have mApps enabled', async () => {
+ const mapp = await justaname.mApps.checkIfMAppIsEnabled({
subname: subnameToBeAdded + '.' + ENS_DOMAIN,
- ebdc: ENS_DOMAIN
+ mApp: MAPP,
+ chainId: CHAIN_ID
})
- expect(subname).toBeTruthy();
+ expect(mapp).toBeTruthy();
})
- it('should append field to ebdc subname', async () => {
- const challenge = await justaname.ebdc.requestAppendEbdcFieldChallenge({
+ it('should append field to mApps subname', async () => {
+ const challenge = await justaname.mApps.requestAppendMAppFieldChallenge({
subname: subnameToBeAdded + '.' + ENS_DOMAIN,
- address: signer.address,
- ensDomain: ENS_DOMAIN,
+ address: mAppSigner.address,
+ mApp: ENS_DOMAIN,
+ chainId: CHAIN_ID
+
})
- const signature = await signer.signMessage(challenge.challenge);
+ const signature = await mAppSigner.signMessage(challenge.challenge);
- const response = await justaname.ebdc.appendEbdcField({
+ const response = await justaname.mApps.appendMAppField({
subname: subnameToBeAdded + '.' + ENS_DOMAIN,
fields: [{
key:'test',
value: 'testValue'
- }]
- }, {
- xAddress: signer.address,
+ }, {
+ key: 'test2',
+ value: 'testValue2'
+ }],
+ }, {
+ xAddress: mAppSigner.address,
xMessage: challenge.challenge,
xSignature: signature
})
@@ -148,27 +271,91 @@ describe('justaname', () => {
expect(response).toBeDefined();
})
- it('should revoke ebdc permission', async () => {
- const subname = await justaname.subnames.getRecordsByFullName({
- fullName: subnameToBeAdded + '.' + ENS_DOMAIN,
+ it("user shoudn't be able to update mApps field", async () => {
+ const challenge = await justaname.siwe.requestChallenge({
+ address: subnameSigner.address,
+ chainId: CHAIN_ID,
+ });
+
+ const signature = await subnameSigner.signMessage(challenge.challenge);
+
+ const response = await justaname.subnames.updateSubname({
+ contentHash: '',
+ username: subnameToBeAdded,
+ chainId: CHAIN_ID,
+ ensDomain: ENS_DOMAIN,
+ addresses: {},
+ text: {
+ [`test2_${MAPP}`]: 'shouldntBeUpdated',
+ }
+ }, {
+ xMessage: challenge.challenge,
+ xAddress: subnameSigner.address,
+ xSignature: signature
+ })
+
+ expect(response.data.textRecords.find((text) => text.key === `test2_${MAPP}`)?.value).toEqual('testValue2');
+ })
+
+ it('should remove field if value is empty', async () => {
+ const challenge = await justaname.mApps.requestAppendMAppFieldChallenge({
+ subname: subnameToBeAdded + '.' + ENS_DOMAIN,
+ address: mAppSigner.address,
+ mApp: ENS_DOMAIN,
+ chainId: CHAIN_ID
+
+ })
+
+ const signature = await mAppSigner.signMessage(challenge.challenge);
+
+ const response = await justaname.mApps.appendMAppField({
+ subname: subnameToBeAdded + '.' + ENS_DOMAIN,
+ fields: [{
+ key:'test',
+ value: ''}],
+ }, {
+ xAddress: mAppSigner.address,
+ xMessage: challenge.challenge,
+ xSignature: signature
+ })
+
+ expect(response.data.textRecords.find((text) => text.key === `test_${MAPP}`)).toBeUndefined();
+ })
+
+
+ it('should revoke mApps permission', async () => {
+ const challenge = await justaname.mApps.requestRevokeMAppPermissionChallenge({
+ subname: subnameToBeAdded + '.' + ENS_DOMAIN,
+ address: subnameSigner.address,
+ mApp: MAPP,
+ chainId: CHAIN_ID
+ })
+
+ const signature = await subnameSigner.signMessage(challenge.challenge);
+
+ const response = await justaname.mApps.revokeMAppPermission({
+ address: subnameSigner.address,
+ signature,
+ message: challenge.challenge
})
- const ebdc = subname.texts.find((text) => text.key === 'ebdc')?.value
- const testJawEth = subname.texts.find((text) => text.key === 'test_jaw.eth')?.value
+ const mApps = response.data.textRecords.find((text) => text.key === 'mApps')?.value
+ const testJawEth = response.data.textRecords.find((text) => text.key === `test_${MAPP}`)?.value
- expect(ebdc).toEqual('{"ebdcs":["jaw.eth"]}')
- expect(testJawEth).toEqual('testValue')
+ expect(mApps).toEqual(`{"mApps":["${MAPP_2}"]}`)
+ expect(testJawEth).toEqual(undefined)
})
it('should revoke subname', async () => {
const challenge = await justaname.siwe.requestChallenge({
address: subnameSigner.address,
+ chainId: CHAIN_ID,
});
const signature = await subnameSigner.signMessage(challenge.challenge);
const response = await justaname.subnames.revokeSubname({
- chainId: 11155111,
+ chainId: CHAIN_ID,
ensDomain: ENS_DOMAIN,
username: subnameToBeAdded
}, {
diff --git a/packages/@justaname.id/siwens/.env b/packages/@justaname.id/siwens/.env
deleted file mode 100644
index 52f24607..00000000
--- a/packages/@justaname.id/siwens/.env
+++ /dev/null
@@ -1,3 +0,0 @@
-PRIVATE_KEY=98fb03611a95be48b6f11bfce7e47d8c8505b7d711e58b75a415483d4330f79a
-PROVIDER_URL=https://sepolia.infura.io/v3/ace886ce4e95478a89220d6ab859d861
-VALID_ENS=jaw.eth
\ No newline at end of file
diff --git a/packages/@justaname.id/siwens/.env.example b/packages/@justaname.id/siwens/.env.example
new file mode 100644
index 00000000..325946da
--- /dev/null
+++ b/packages/@justaname.id/siwens/.env.example
@@ -0,0 +1,3 @@
+SIWENS_PRIVATE_KEY=
+SIWENS_PROVIDER_URL=
+SIWENS_VALID_ENS=
\ No newline at end of file
diff --git a/packages/@justaname.id/siwens/.gitignore b/packages/@justaname.id/siwens/.gitignore
new file mode 100644
index 00000000..2eea525d
--- /dev/null
+++ b/packages/@justaname.id/siwens/.gitignore
@@ -0,0 +1 @@
+.env
\ No newline at end of file
diff --git a/packages/@justaname.id/siwens/src/test/siwens.spec.ts b/packages/@justaname.id/siwens/src/test/siwens.spec.ts
index 9798c586..cf19630c 100644
--- a/packages/@justaname.id/siwens/src/test/siwens.spec.ts
+++ b/packages/@justaname.id/siwens/src/test/siwens.spec.ts
@@ -1,5 +1,5 @@
import { ethers } from 'ethers';
-import dotenv from 'dotenv';
+import * as dotenv from 'dotenv';
import {
SIWENS,
InvalidTimeException,
@@ -7,9 +7,9 @@ import {
} from '../';
dotenv.config();
-const pk = process.env['PRIVATE_KEY'] as string;
+const pk = process.env['SIWENS_PRIVATE_KEY'] as string;
const signer = new ethers.Wallet(pk);
-const PROVIDER_URL = process.env['PROVIDER_URL'] as string;
+const PROVIDER_URL = process.env['SIWENS_PROVIDER_URL'] as string;
const DOMAIN = 'justaname.id';
const URI = 'https://' + DOMAIN;
const ADDRESS = signer.address;
@@ -20,7 +20,7 @@ const VALID_TTL = 60 * 60 * 24 * 1000; // 1 day
const TTL_LESS_THAN_ZERO = -1;
const TTL_GREATER_THAN_MAX_SAFE_INTEGER = Number.MAX_SAFE_INTEGER + 1;
const INVALID_ENS = 'justaname';
-const VALID_ENS = process.env['VALID_ENS'] as string;
+const VALID_ENS = process.env['SIWENS_VALID_ENS'] as string;
describe('SIWENS', () => {