Skip to content
This repository has been archived by the owner on Oct 7, 2024. It is now read-only.

Commit

Permalink
refactor: split api.ts (#319)
Browse files Browse the repository at this point in the history
  • Loading branch information
danroc authored May 28, 2024
1 parent 96e9798 commit 4edbbd7
Show file tree
Hide file tree
Showing 8 changed files with 334 additions and 313 deletions.
312 changes: 0 additions & 312 deletions src/api.ts

This file was deleted.

2 changes: 1 addition & 1 deletion src/api.test.ts → src/api/account.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { assert } from 'superstruct';

import { KeyringAccountStruct } from './api';
import { KeyringAccountStruct } from './account';

const supportedKeyringAccountTypes = Object.keys(
KeyringAccountStruct.schema.type.schema,
Expand Down
73 changes: 73 additions & 0 deletions src/api/account.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
import { JsonStruct } from '@metamask/utils';
import type { Infer } from 'superstruct';
import { array, enums, record, string } from 'superstruct';

import { object } from '../superstruct';
import { UuidStruct } from '../utils';

/**
* Supported Ethereum account types.
*/
export enum EthAccountType {
Eoa = 'eip155:eoa',
Erc4337 = 'eip155:erc4337',
}

/**
* Supported Bitcoin account types.
*/
export enum BtcAccountType {
P2wpkh = 'bip122:p2wpkh',
}

/**
* Supported account types.
*/
export type KeyringAccountType =
| `${EthAccountType.Eoa}`
| `${EthAccountType.Erc4337}`
| `${BtcAccountType.P2wpkh}`;

/**
* A struct which represents a Keyring account object. It is abstract enough to
* be used with any blockchain. Specific blockchain account types should extend
* this struct.
*
* See {@link KeyringAccount}.
*/
export const KeyringAccountStruct = object({
/**
* Account ID (UUIDv4).
*/
id: UuidStruct,

/**
* Account type.
*/
type: enums([
`${EthAccountType.Eoa}`,
`${EthAccountType.Erc4337}`,
`${BtcAccountType.P2wpkh}`,
]),

/**
* Account main address.
*/
address: string(),

/**
* Account options.
*/
options: record(string(), JsonStruct),

/**
* Account supported methods.
*/
methods: array(string()),
});

/**
* Keyring Account type represents an account and its properties from the
* point of view of the keyring.
*/
export type KeyringAccount = Infer<typeof KeyringAccountStruct>;
Loading

0 comments on commit 4edbbd7

Please sign in to comment.