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

refactor: split api.ts #319

Merged
merged 1 commit into from
May 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading