From: Chris Duncan Date: Wed, 5 Aug 2026 01:21:19 +0000 (-0700) Subject: Validate wallet refresh frontier subtype and fix account subtype validation. X-Git-Url: https://git.codecow.com/?a=commitdiff_plain;h=6a1d24c0f60a192efb4c4ebc2ec731f27bd5ef81;p=libnemo.git Validate wallet refresh frontier subtype and fix account subtype validation. --- diff --git a/src/lib/account/refresh.ts b/src/lib/account/refresh.ts index f956dc8..3fc558c 100644 --- a/src/lib/account/refresh.ts +++ b/src/lib/account/refresh.ts @@ -46,7 +46,7 @@ export async function _refresh (account: Account, rpc: unknown): Promise { throw new Error('Confirmed frontier block info subtype not found') } const confirmedFrontierSubtype = resConfirmedFrontierBlockInfo.subtype - if (!['change', 'epoch', 'open', 'receive', 'send'].includes(confirmedFrontierSubtype) { + if (!['change', 'epoch', 'open', 'receive', 'send'].includes(confirmedFrontierSubtype)) { throw new RangeError('Invalid subtype for confirmed frontier block', { cause: confirmedFrontierSubtype }) } if (!('contents' in resConfirmedFrontierBlockInfo) || resConfirmedFrontierBlockInfo.contents == null || typeof resConfirmedFrontierBlockInfo.contents !== 'object') { @@ -77,7 +77,7 @@ export async function _refresh (account: Account, rpc: unknown): Promise { throw new Error('Frontier block info subtype not found') } const frontierSubtype = resFrontierBlockInfo.subtype - if (!['change', 'epoch', 'open', 'receive', 'send'].includes(frontierSubtype) { + if (!['change', 'epoch', 'open', 'receive', 'send'].includes(frontierSubtype)) { throw new RangeError('Invalid subtype for frontier block', { cause: frontierSubtype }) } if (!('contents' in resFrontierBlockInfo) || resFrontierBlockInfo.contents == null || typeof resFrontierBlockInfo.contents !== 'object') { diff --git a/src/lib/wallet/refresh.ts b/src/lib/wallet/refresh.ts index 24e4dcf..ca9513a 100644 --- a/src/lib/wallet/refresh.ts +++ b/src/lib/wallet/refresh.ts @@ -49,6 +49,9 @@ export async function _refresh (wallet: Wallet, rpc: unknown, from: unknown, to: if (frontiers[account.address] != null) { account.frontier = frontiers[account.address] const { subtype, contents: { balance, link, previous, representative, signature } } = blocks[account.frontier] + if (!['change', 'epoch', 'open', 'receive', 'send'].includes(subtype)) { + throw new RangeError('Invalid subtype for account frontier block', { cause: subtype }) + } account.representative = representative const frontierBlock = new Block(account, balance, previous, representative) if (typeof frontierBlock[subtype] !== 'function') {