Skip to content

Commit

Permalink
Revert "feat: allow multiple address per account (#315)" (#342)
Browse files Browse the repository at this point in the history
This reverts commit f6b3701.
  • Loading branch information
danroc committed Jun 11, 2024
1 parent a90b2b2 commit 37409d7
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 57 deletions.
32 changes: 3 additions & 29 deletions src/api/account.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { JsonStruct } from '@metamask/utils';
import type { Infer } from 'superstruct';
import { array, enums, record, string, union } from 'superstruct';
import { array, enums, record, string } from 'superstruct';

import { object } from '../superstruct';
import { UuidStruct } from '../utils';
Expand Down Expand Up @@ -51,35 +51,9 @@ export const KeyringAccountStruct = object({
]),

/**
* Account addresses. It can be a single address or a map of addresses per
* chain.
*
* If the address is a string, it's assumed to be under the 'eip155'
* namespace. Otherwise, it must be a map of addresses per chain, where the
* key is the chain ID (CAIP-2) and the value is an array of addresses.
*
* @example
* ```ts
* address: {
* // Different addresses per chain.
* 'eip155:1': ['0x1234...'],
* 'eip155:137': ['0x5678...'],
* }
* ```
* @example
* ```ts
* address: {
* // The address is the same across all 'eip155' chains.
* 'eip155': ['0x1234...'],
* }
* ```
* @example
* ```ts
* // Assumed to be under the 'eip155' namespace.
* address: '0x1234...',
* ```
* Account main address.
*/
address: union([string(), record(string(), array(string()))]),
address: string(),

/**
* Account options.
Expand Down
7 changes: 1 addition & 6 deletions src/api/keyring.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,17 +81,12 @@ export type Keyring = {
/**
* Filter supported chains for a given account.
*
* See {@link KeyringAccount}.
*
* @deprecated Use the keys of the `address` map of the account object to
* indicate the supported chains. This method will be removed in a future
* version of the Keyring API.
* @param id - ID of the account to be checked.
* @param chains - List of chains (CAIP-2) to be checked.
* @returns A Promise that resolves to a filtered list of CAIP-2 IDs
* representing the supported chains.
*/
filterAccountChains?(id: string, chains: string[]): Promise<string[]>;
filterAccountChains(id: string, chains: string[]): Promise<string[]>;

/**
* Update an account.
Expand Down
20 changes: 1 addition & 19 deletions src/rpc-handler.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,25 +133,7 @@ describe('handleKeyringRequest', () => {
expect(result).toBe('FilterSupportedChains result');
});

it('fails because `keyring_filterAccountChains` is not implemented', async () => {
const request: JsonRpcRequest = {
jsonrpc: '2.0',
id: '7c507ff0-365f-4de0-8cd5-eb83c30ebda4',
method: 'keyring_filterAccountChains',
params: {
id: '4f983fa2-4f53-4c63-a7c2-f9a5ed750041',
chains: ['chain1', 'chain2'],
},
};

const { filterAccountChains, ...partialKeyring } = keyring;

await expect(handleKeyringRequest(partialKeyring, request)).rejects.toThrow(
'Method not supported: keyring_filterAccountChains',
);
});

it('calls keyring_updateAccount', async () => {
it('calls `keyring_updateAccount`', async () => {
const request: JsonRpcRequest = {
jsonrpc: '2.0',
id: '7c507ff0-365f-4de0-8cd5-eb83c30ebda4',
Expand Down
3 changes: 0 additions & 3 deletions src/rpc-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,6 @@ async function dispatchRequest(
}

case KeyringRpcMethod.FilterAccountChains: {
if (keyring.filterAccountChains === undefined) {
throw new MethodNotSupportedError(request.method);
}
assert(request, FilterAccountChainsStruct);
return keyring.filterAccountChains(
request.params.id,
Expand Down

0 comments on commit 37409d7

Please sign in to comment.