Skip to content

Commit

Permalink
swap .d.ts type files for .ts files
Browse files Browse the repository at this point in the history
  • Loading branch information
netbonus committed Oct 16, 2024
1 parent 790c3a6 commit 81435be
Show file tree
Hide file tree
Showing 44 changed files with 366 additions and 144 deletions.
1 change: 1 addition & 0 deletions src/api/addressTags.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Client } from '../client';
import { MAX_ADDR } from '../constants';
import { AddressTag } from '../types';
import { queue } from './utilities';

/**
Expand Down
1 change: 1 addition & 0 deletions src/api/addresses.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
MAX_ADDR,
SOLANA_DERIVATION,
} from '../constants';
import { GetAddressesRequestParams, WalletPath } from '../types';
import {
getStartPath,
parseDerivationPathComponents,
Expand Down
6 changes: 6 additions & 0 deletions src/api/signing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ import {
DEFAULT_ETH_DERIVATION,
SOLANA_DERIVATION,
} from '../constants';
import {
SignRequestParams,
SignData,
EIP712MessagePayload,
BitcoinSignPayload,
} from '../types';
import { isEIP712Payload, queue } from './utilities';

export const sign = async (
Expand Down
1 change: 1 addition & 0 deletions src/api/wallets.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { ActiveWallets } from '../types';
import { queue } from './utilities';

/**
Expand Down
12 changes: 12 additions & 0 deletions src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,18 @@ import {
import { buildRetryWrapper } from './shared/functions';
import { getPubKeyBytes } from './shared/utilities';
import { validateEphemeralPub } from './shared/validators';
import {
KeyPair,
ActiveWallets,
GetAddressesRequestParams,
SignRequestParams,
SignData,
AddKvRecordsRequestParams,
GetKvRecordsRequestParams,
GetKvRecordsData,
RemoveKvRecordsRequestParams,
FetchEncDataRequest,
} from './types';
import { getP256KeyPair, getP256KeyPairFromPub, randomBytes } from './util';

/**
Expand Down
1 change: 1 addition & 0 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
LatticeSignEncoding,
LatticeSignHash,
} from './protocol/latticeConstants';
import { FirmwareConstants, FirmwareArr, ActiveWallets } from './types';

/**
* Externally exported constants used for building requests
Expand Down
5 changes: 5 additions & 0 deletions src/functions/addKvRecords.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ import {
validateKvRecord,
validateKvRecords,
} from '../shared/validators';
import {
AddKvRecordsRequestFunctionParams,
KVRecords,
FirmwareConstants,
} from '../types';

/**
* `addKvRecords` takes in a set of key-value records and sends a request to add them to the
Expand Down
1 change: 1 addition & 0 deletions src/functions/connect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
validateDeviceId,
validateKey,
} from '../shared/validators';
import { ConnectRequestFunctionParams, KeyPair, ActiveWallets } from '../types';
import { aes256_decrypt, getP256KeyPairFromPub } from '../util';

export async function connect({
Expand Down
4 changes: 4 additions & 0 deletions src/functions/fetchActiveWallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ import {
validateActiveWallets,
validateConnectedClient,
} from '../shared/validators';
import {
FetchActiveWalletRequestFunctionParams,
ActiveWallets,
} from '../types';

/**
* Fetch the active wallet in the device.
Expand Down
7 changes: 7 additions & 0 deletions src/functions/fetchEncData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@ import {
validateStartPath,
validateWallet,
} from '../shared/validators';
import {
FetchEncDataRequestFunctionParams,
EIP2335KeyExportReq,
FirmwareVersion,
Wallet,
EIP2335KeyExportData,
} from '../types';

const { ENC_DATA } = EXTERNAL;
const ENC_DATA_ERR_STR =
Expand Down
5 changes: 5 additions & 0 deletions src/functions/getAddresses.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ import {
validateStartPath,
validateWallet,
} from '../shared/validators';
import {
GetAddressesRequestFunctionParams,
FirmwareConstants,
Wallet,
} from '../types';
import { isValidAssetPath } from '../util';

/**
Expand Down
5 changes: 5 additions & 0 deletions src/functions/getKvRecords.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@ import {
encryptedSecureRequest,
} from '../protocol';
import { validateConnectedClient } from '../shared/validators';
import {
GetKvRecordsRequestFunctionParams,
GetKvRecordsData,
FirmwareConstants,
} from '../types';

export async function getKvRecords({
client,
Expand Down
1 change: 1 addition & 0 deletions src/functions/pair.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
} from '../protocol';
import { getPubKeyBytes } from '../shared/utilities';
import { validateConnectedClient } from '../shared/validators';
import { PairRequestParams, KeyPair } from '../types';
import { generateAppSecret, toPaddedDER } from '../util';

/**
Expand Down
4 changes: 4 additions & 0 deletions src/functions/removeKvRecords.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ import {
encryptedSecureRequest,
} from '../protocol';
import { validateConnectedClient } from '../shared/validators';
import {
RemoveKvRecordsRequestFunctionParams,
FirmwareConstants,
} from '../types';

/**
* `removeKvRecords` takes in an array of ids and sends a request to remove them from the Lattice.
Expand Down
8 changes: 8 additions & 0 deletions src/functions/sign.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,14 @@ import {
import { buildTransaction } from '../shared/functions';
import { validateConnectedClient, validateWallet } from '../shared/validators';
import { parseDER } from '../util';
import {
SignRequestFunctionParams,
SigningRequestResponse,
EncodeSignRequestParams,
DecodeSignResponseParams,
SignData,
BitcoinSignRequest,
} from '../types';

/**
* `sign` builds and sends a request for signing to the device.
Expand Down
8 changes: 8 additions & 0 deletions src/protocol/secureMessages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,14 @@ import {
} from '../util';
import { getEphemeralId, request } from '../shared/functions';
import { validateEphemeralPub } from '../shared/validators';
import {
DecryptedResponse,
LatticeSecureRequestPayload,
LatticeMessageHeader,
LatticeSecureRequest,
LatticeSecureConnectRequestPayloadData,
LatticeSecureDecryptedResponse,
} from '../types';

const { msgSizes } = Constants;
const { secure: szs } = msgSizes;
Expand Down
1 change: 1 addition & 0 deletions src/shared/functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
shouldUseEVMLegacyConverter,
} from './predicates';
import { validateRequestError } from './validators';
import { Currency, FirmwareConstants, RequestParams } from '../types';

export const buildTransaction = ({
data,
Expand Down
1 change: 1 addition & 0 deletions src/shared/predicates.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { LatticeResponseCode } from '../protocol';
import { FirmwareVersion, FirmwareConstants } from '../types';
import { isFWSupported } from './utilities';

export const isDeviceBusy = (responseCode: number) =>
Expand Down
1 change: 1 addition & 0 deletions src/shared/utilities.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { HARDENED_OFFSET } from '../constants';
import { KeyPair, ActiveWallets, FirmwareVersion } from '../types';

/**
* Get 64 bytes representing the public key This is the uncompressed key without the leading 04
Expand Down
9 changes: 9 additions & 0 deletions src/shared/validators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,15 @@ import { Client } from '../client';
import { ASCII_REGEX, EMPTY_WALLET_UID, MAX_ADDR } from '../constants';
import { isUInt4 } from '../util';
import isEmpty from 'lodash/isEmpty';
import {
FirmwareConstants,
FirmwareVersion,
LatticeError,
Wallet,
KeyPair,
ActiveWallets,
KVRecords,
} from '../types';

export const validateIsUInt4 = (n?: number) => {
if (typeof n !== 'number' || !isUInt4(n)) {
Expand Down
9 changes: 0 additions & 9 deletions src/types/addKvRecords.d.ts

This file was deleted.

13 changes: 13 additions & 0 deletions src/types/addKvRecords.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { Client } from '../client';
import { KVRecords } from './shared';

export interface AddKvRecordsRequestParams {
records: KVRecords;
type?: number;
caseSensitive?: boolean;
}

export interface AddKvRecordsRequestFunctionParams
extends AddKvRecordsRequestParams {
client: Client;
}
20 changes: 11 additions & 9 deletions src/types/client.d.ts → src/types/client.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
type Currency = keyof typeof CURRENCIES;
import { CURRENCIES } from '../constants';

type SigningPath = number[];
export type Currency = keyof typeof CURRENCIES;

interface SignData {
export type SigningPath = number[];

export interface SignData {
tx?: string;
txHash?: string;
changeRecipient?: string;
Expand All @@ -16,9 +18,9 @@ interface SignData {
err?: string;
}

type SigningRequestResponse = SignData | { pubkey: null; sig: null };
export type SigningRequestResponse = SignData | { pubkey: null; sig: null };

interface TransactionPayload {
export interface TransactionPayload {
type: number;
gasPrice: number;
nonce: number;
Expand All @@ -30,7 +32,7 @@ interface TransactionPayload {
maxPriorityFeePerGas: number;
}

interface Wallet {
export interface Wallet {
/** 32 byte id */
uid: Buffer;
/** 20 char (max) string */
Expand All @@ -41,19 +43,19 @@ interface Wallet {
external: boolean;
}

interface ActiveWallets {
export interface ActiveWallets {
internal: Wallet;
external: Wallet;
}

interface RequestParams {
export interface RequestParams {
url: string;
payload: any; //TODO Fix this any
timeout?: number;
retries?: number;
}

interface ClientStateData {
export interface ClientStateData {
activeWallets: ActiveWallets;
ephemeralPub: Buffer;
fwVersion: Buffer;
Expand Down
7 changes: 0 additions & 7 deletions src/types/connect.d.ts

This file was deleted.

9 changes: 9 additions & 0 deletions src/types/connect.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { Client } from '../client';

export interface ConnectRequestParams {
id: string;
}

export interface ConnectRequestFunctionParams extends ConnectRequestParams {
client: Client;
}
7 changes: 0 additions & 7 deletions src/types/fetchActiveWallet.d.ts

This file was deleted.

9 changes: 9 additions & 0 deletions src/types/fetchActiveWallet.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { Client } from '../client';

export interface FetchActiveWalletRequestFunctionParams {
client: Client;
}

export interface ValidatedFetchActiveWalletRequest {
sharedSecret: Buffer;
}
10 changes: 6 additions & 4 deletions src/types/fetchEncData.d.ts → src/types/fetchEncData.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
interface EIP2335KeyExportReq {
import { Client } from '../client';

export interface EIP2335KeyExportReq {
path: number[];
c?: number;
kdf?: number;
walletUID?: Buffer;
}

interface FetchEncDataRequest {
export interface FetchEncDataRequest {
schema: number;
params: EIP2335KeyExportReq; // NOTE: This is a union, but only one type of request exists currently
}

interface FetchEncDataRequestFunctionParams extends FetchEncDataRequest {
export interface FetchEncDataRequestFunctionParams extends FetchEncDataRequest {
client: Client;
}

interface EIP2335KeyExportData {
export interface EIP2335KeyExportData {
iterations: number;
cipherText: Buffer;
salt: Buffer;
Expand Down
Loading

0 comments on commit 81435be

Please sign in to comment.