Skip to content

Commit

Permalink
fixes type errors
Browse files Browse the repository at this point in the history
  • Loading branch information
netbonus committed Oct 16, 2024
1 parent 81435be commit bee0a26
Show file tree
Hide file tree
Showing 10 changed files with 21 additions and 16 deletions.
11 changes: 6 additions & 5 deletions src/api/signing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
SignData,
EIP712MessagePayload,
BitcoinSignPayload,
Currency,
} from '../types';
import { isEIP712Payload, queue } from './utilities';

Expand Down Expand Up @@ -45,8 +46,8 @@ export const signMessage = async (
payload,
...overrides,
},
currency: CURRENCIES.ETH_MSG,
};
currency: CURRENCIES.ETH_MSG as Currency,
} as SignRequestParams & { data: {protocol: string}};

if (isEIP712Payload(payload)) {
tx.data.protocol = 'eip712';
Expand All @@ -63,7 +64,7 @@ export const signBtcLegacyTx = async (
signerPath: BTC_LEGACY_DERIVATION,
...payload,
},
currency: 'BTC',
currency: 'BTC' as Currency,
};
return queue((client) => client.sign(tx));
};
Expand All @@ -76,7 +77,7 @@ export const signBtcSegwitTx = async (
signerPath: BTC_SEGWIT_DERIVATION,
...payload,
},
currency: 'BTC',
currency: 'BTC'as Currency,
};
return queue((client) => client.sign(tx));
};
Expand All @@ -89,7 +90,7 @@ export const signBtcWrappedSegwitTx = async (
signerPath: BTC_WRAPPED_SEGWIT_DERIVATION,
...payload,
},
currency: 'BTC',
currency: 'BTC'as Currency,
};
return queue((client) => client.sign(tx));
};
Expand Down
4 changes: 2 additions & 2 deletions src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ export class Client {
activeWallets,
}: {
deviceId?: string;
ephemeralPub?: Buffer;
ephemeralPub?: KeyPair;
url?: string;
isPaired?: boolean;
fwVersion?: Buffer;
Expand Down Expand Up @@ -390,7 +390,7 @@ export class Client {
capabilities: this.activeWallets.external.capabilities,
},
},
ephemeralPub: this.ephemeralPub?.getPublic()?.encode('hex'),
ephemeralPub: this.ephemeralPub?.getPublic()?.encode('hex', true),
fwVersion: this.fwVersion?.toString('hex'),
deviceId: this.deviceId,
name: this.name,
Expand Down
3 changes: 2 additions & 1 deletion src/functions/connect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export async function connect({
}: ConnectRequestFunctionParams): Promise<boolean> {
const { deviceId, key, baseUrl } = validateConnectRequest({
deviceId: id,
// @ts-expect-error - private access
key: client.key,
baseUrl: client.baseUrl,
});
Expand Down Expand Up @@ -96,7 +97,7 @@ export const decodeConnectResponse = (
isPaired: boolean;
fwVersion: Buffer;
activeWallets: ActiveWallets | undefined;
ephemeralPub: Buffer;
ephemeralPub: KeyPair;
} => {
let off = 0;
const isPaired =
Expand Down
5 changes: 3 additions & 2 deletions src/protocol/secureMessages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import {
LatticeSecureRequest,
LatticeSecureConnectRequestPayloadData,
LatticeSecureDecryptedResponse,
KeyPair,
} from '../types';

const { msgSizes } = Constants;
Expand Down Expand Up @@ -101,7 +102,7 @@ export async function encryptedSecureRequest({
data: Buffer;
requestType: LatticeSecureEncryptedRequestType;
sharedSecret: Buffer;
ephemeralPub: Buffer;
ephemeralPub: KeyPair;
url: string;
}): Promise<DecryptedResponse> {
// Generate a random message id for internal tracking
Expand Down Expand Up @@ -268,7 +269,7 @@ function serializeSecureRequestEncryptedPayloadData({
}: {
data: Buffer;
requestType: LatticeSecureEncryptedRequestType;
ephemeralPub: Buffer;
ephemeralPub: KeyPair;
sharedSecret: Buffer;
}): Buffer {
// Sanity checks request size
Expand Down
2 changes: 1 addition & 1 deletion src/shared/functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ export const retryWrapper = async ({ fn, params, retries, client }) => {
* @returns Buffer
*/
export const getEphemeralId = (sharedSecret: Buffer) => {
// EphemId is the first 4 bytes of the hash of the shared secret
// EphemId is the first 4 bytes of the hash of the shared secret
const hash = Buffer.from(sha256().update(sharedSecret).digest('hex'), 'hex');
return parseInt(hash.slice(0, 4).toString('hex'), 16);
};
2 changes: 1 addition & 1 deletion src/shared/utilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { KeyPair, ActiveWallets, FirmwareVersion } from '../types';
*/
export const getPubKeyBytes = (key: KeyPair, LE = false) => {
const k = key.getPublic();
const p = k.encode('hex');
const p = k.encode('hex', true);
const pb = Buffer.from(p, 'hex');
if (LE === true) {
// Need to flip X and Y components to little endian
Expand Down
2 changes: 1 addition & 1 deletion src/shared/validators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ export const validateConnectedClient = (client: Client) => {
};
};

export const validateEphemeralPub = (ephemeralPub?: Buffer) => {
export const validateEphemeralPub = (ephemeralPub?: KeyPair) => {
if (!ephemeralPub) {
throw new Error(
'`ephemeralPub` (ephemeral public key) is required. Please reconnect.',
Expand Down
3 changes: 2 additions & 1 deletion src/types/client.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { CURRENCIES } from '../constants';
import { KeyPair } from './shared';

export type Currency = keyof typeof CURRENCIES;

Expand Down Expand Up @@ -57,7 +58,7 @@ export interface RequestParams {

export interface ClientStateData {
activeWallets: ActiveWallets;
ephemeralPub: Buffer;
ephemeralPub: KeyPair;
fwVersion: Buffer;
deviceId: string;
name: string;
Expand Down
2 changes: 1 addition & 1 deletion src/types/shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,5 @@ export type WalletPath = [number, number, number, number, number];

export interface DecryptedResponse {
decryptedData: Buffer;
newEphemeralPub: Buffer;
newEphemeralPub: KeyPair;
}
3 changes: 2 additions & 1 deletion src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import {
isValid4ByteResponse,
isValidBlockExplorerResponse,
} from './shared/validators';
import { KeyPair } from './types';

const { COINS, PURPOSES } = BIP_CONSTANTS;
const EC = elliptic.ec;
Expand Down Expand Up @@ -250,7 +251,7 @@ export const getP256KeyPair = function (priv) {
};

/** @internal */
export const getP256KeyPairFromPub = function (pub) {
export const getP256KeyPairFromPub = function (pub): KeyPair {
if (ec === undefined) ec = new EC('p256');
return ec.keyFromPublic(pub, 'hex');
};
Expand Down

0 comments on commit bee0a26

Please sign in to comment.