Skip to content

Commit

Permalink
add more TSDocs
Browse files Browse the repository at this point in the history
  • Loading branch information
adonesky1 committed Nov 7, 2024
1 parent be5a235 commit 8194afd
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ import { getUniqueArrayItems, mergeScopes } from '../scope/transform';
import type { InternalScopesObject, InternalScopeString } from '../scope/types';
import { parseScopeString } from '../scope/types';

/**
* Checks if a scope string is either an EIP155 or wallet namespaced scope string.
* @param scopeString - The scope string to check.
* @returns True if the scope string is an EIP155 or wallet namespaced scope string, false otherwise.
*/
const isEip155ScopeString = (scopeString: InternalScopeString) => {
const { namespace } = parseScopeString(scopeString);

Expand All @@ -20,6 +25,11 @@ const isEip155ScopeString = (scopeString: InternalScopeString) => {
);
};

/**
* Gets the Ethereum (EIP155 namespaced) accounts from the required and optional scopes.
* @param caip25CaveatValue - The CAIP-25 caveat value to get the Ethereum accounts from.
* @returns An array of Ethereum accounts.
*/
export const getEthAccounts = (
caip25CaveatValue: Pick<
Caip25CaveatValue,
Expand All @@ -45,6 +55,12 @@ export const getEthAccounts = (
return getUniqueArrayItems(ethAccounts);
};

/**
* Sets the Ethereum (EIP155 namespaced) accounts for the given scopes object.
* @param scopesObject - The scopes object to set the Ethereum accounts for.
* @param accounts - The Ethereum accounts to set.
* @returns The updated scopes object with the Ethereum accounts set.
*/
const setEthAccountsForScopesObject = (
scopesObject: InternalScopesObject,
accounts: Hex[],
Expand Down Expand Up @@ -78,6 +94,12 @@ const setEthAccountsForScopesObject = (
return updatedScopesObject;
};

/**
* Sets the Ethereum (EIP155 namespaced) accounts for the given CAIP-25 caveat value.
* @param caip25CaveatValue - The CAIP-25 caveat value to set the Ethereum accounts for.
* @param accounts - The Ethereum accounts to set.
* @returns The updated CAIP-25 caveat value with the Ethereum accounts set.
*/
export const setEthAccounts = (
caip25CaveatValue: Caip25CaveatValue,
accounts: Hex[],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ import { getUniqueArrayItems, mergeScopes } from '../scope/transform';
import type { InternalScopesObject, InternalScopeString } from '../scope/types';
import { parseScopeString } from '../scope/types';

/**
* Gets the Ethereum (EIP155 namespaced) chainIDs from the required and optional scopes.
* @param caip25CaveatValue - The CAIP-25 caveat value from which to get the Ethereum chainIDs.
* @returns An array of Ethereum chainIDs.
*/
export const getPermittedEthChainIds = (
caip25CaveatValue: Pick<
Caip25CaveatValue,
Expand All @@ -34,6 +39,12 @@ export const getPermittedEthChainIds = (
return getUniqueArrayItems(ethChainIds);
};

/**
* Adds an Ethereum (EIP155 namespaced) chainID to the required and optional scopes.
* @param caip25CaveatValue - The CAIP-25 caveat value to add the Ethereum chainID to.
* @param chainId - The Ethereum chainID to add.
* @returns The updated CAIP-25 caveat value with the added Ethereum chainID.
*/
export const addPermittedEthChainId = (
caip25CaveatValue: Caip25CaveatValue,
chainId: Hex,
Expand Down Expand Up @@ -64,6 +75,12 @@ export const addPermittedEthChainId = (
};
};

/**
* Filters the scopes object to only include the scopes for the given chainIDs.
* @param scopesObject - The scopes object to filter.
* @param chainIds - The chainIDs to filter the scopes object by.
* @returns The filtered scopes object.
*/
const filterEthScopesObjectByChainId = (
scopesObject: InternalScopesObject,
chainIds: Hex[],
Expand All @@ -89,6 +106,12 @@ const filterEthScopesObjectByChainId = (
return updatedScopesObject;
};

/**
* Sets the permitted Ethereum (EIP155 namespaced) chainIDs for the required and optional scopes.
* @param caip25CaveatValue - The CAIP-25 caveat value to set the permitted Ethereum chainIDs for.
* @param chainIds - The Ethereum chainIDs to set as permitted.
* @returns The updated CAIP-25 caveat value with the permitted Ethereum chainIDs.
*/
export const setPermittedEthChainIds = (
caip25CaveatValue: Caip25CaveatValue,
chainIds: Hex[],
Expand Down

0 comments on commit 8194afd

Please sign in to comment.