From bee0a26babc4a3caf727eeab7be9ff94c6cc7761 Mon Sep 17 00:00:00 2001 From: netbonus <151201453+netbonus@users.noreply.github.com> Date: Wed, 16 Oct 2024 19:20:35 -0400 Subject: [PATCH] fixes type errors --- src/api/signing.ts | 11 ++++++----- src/client.ts | 4 ++-- src/functions/connect.ts | 3 ++- src/protocol/secureMessages.ts | 5 +++-- src/shared/functions.ts | 2 +- src/shared/utilities.ts | 2 +- src/shared/validators.ts | 2 +- src/types/client.ts | 3 ++- src/types/shared.ts | 2 +- src/util.ts | 3 ++- 10 files changed, 21 insertions(+), 16 deletions(-) diff --git a/src/api/signing.ts b/src/api/signing.ts index d44f4a32..333a0342 100644 --- a/src/api/signing.ts +++ b/src/api/signing.ts @@ -12,6 +12,7 @@ import { SignData, EIP712MessagePayload, BitcoinSignPayload, + Currency, } from '../types'; import { isEIP712Payload, queue } from './utilities'; @@ -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'; @@ -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)); }; @@ -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)); }; @@ -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)); }; diff --git a/src/client.ts b/src/client.ts index c80d525a..ffdbf491 100644 --- a/src/client.ts +++ b/src/client.ts @@ -352,7 +352,7 @@ export class Client { activeWallets, }: { deviceId?: string; - ephemeralPub?: Buffer; + ephemeralPub?: KeyPair; url?: string; isPaired?: boolean; fwVersion?: Buffer; @@ -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, diff --git a/src/functions/connect.ts b/src/functions/connect.ts index a430225a..8f4a4d55 100644 --- a/src/functions/connect.ts +++ b/src/functions/connect.ts @@ -15,6 +15,7 @@ export async function connect({ }: ConnectRequestFunctionParams): Promise { const { deviceId, key, baseUrl } = validateConnectRequest({ deviceId: id, + // @ts-expect-error - private access key: client.key, baseUrl: client.baseUrl, }); @@ -96,7 +97,7 @@ export const decodeConnectResponse = ( isPaired: boolean; fwVersion: Buffer; activeWallets: ActiveWallets | undefined; - ephemeralPub: Buffer; + ephemeralPub: KeyPair; } => { let off = 0; const isPaired = diff --git a/src/protocol/secureMessages.ts b/src/protocol/secureMessages.ts index b2c4f1a7..a4dc6d4e 100644 --- a/src/protocol/secureMessages.ts +++ b/src/protocol/secureMessages.ts @@ -41,6 +41,7 @@ import { LatticeSecureRequest, LatticeSecureConnectRequestPayloadData, LatticeSecureDecryptedResponse, + KeyPair, } from '../types'; const { msgSizes } = Constants; @@ -101,7 +102,7 @@ export async function encryptedSecureRequest({ data: Buffer; requestType: LatticeSecureEncryptedRequestType; sharedSecret: Buffer; - ephemeralPub: Buffer; + ephemeralPub: KeyPair; url: string; }): Promise { // Generate a random message id for internal tracking @@ -268,7 +269,7 @@ function serializeSecureRequestEncryptedPayloadData({ }: { data: Buffer; requestType: LatticeSecureEncryptedRequestType; - ephemeralPub: Buffer; + ephemeralPub: KeyPair; sharedSecret: Buffer; }): Buffer { // Sanity checks request size diff --git a/src/shared/functions.ts b/src/shared/functions.ts index 331e4b24..2864ef28 100644 --- a/src/shared/functions.ts +++ b/src/shared/functions.ts @@ -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); }; diff --git a/src/shared/utilities.ts b/src/shared/utilities.ts index 20561e79..ef9bd40c 100644 --- a/src/shared/utilities.ts +++ b/src/shared/utilities.ts @@ -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 diff --git a/src/shared/validators.ts b/src/shared/validators.ts index 5078de32..2f191047 100644 --- a/src/shared/validators.ts +++ b/src/shared/validators.ts @@ -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.', diff --git a/src/types/client.ts b/src/types/client.ts index d72faf57..c08eb0f2 100644 --- a/src/types/client.ts +++ b/src/types/client.ts @@ -1,4 +1,5 @@ import { CURRENCIES } from '../constants'; +import { KeyPair } from './shared'; export type Currency = keyof typeof CURRENCIES; @@ -57,7 +58,7 @@ export interface RequestParams { export interface ClientStateData { activeWallets: ActiveWallets; - ephemeralPub: Buffer; + ephemeralPub: KeyPair; fwVersion: Buffer; deviceId: string; name: string; diff --git a/src/types/shared.ts b/src/types/shared.ts index a2eac0f5..958f958e 100644 --- a/src/types/shared.ts +++ b/src/types/shared.ts @@ -21,5 +21,5 @@ export type WalletPath = [number, number, number, number, number]; export interface DecryptedResponse { decryptedData: Buffer; - newEphemeralPub: Buffer; + newEphemeralPub: KeyPair; } diff --git a/src/util.ts b/src/util.ts index 7c3ccbef..c6fcab8a 100644 --- a/src/util.ts +++ b/src/util.ts @@ -25,6 +25,7 @@ import { isValid4ByteResponse, isValidBlockExplorerResponse, } from './shared/validators'; +import { KeyPair } from './types'; const { COINS, PURPOSES } = BIP_CONSTANTS; const EC = elliptic.ec; @@ -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'); };