From aade8d46689889831b0b297b609ba47cb6a27282 Mon Sep 17 00:00:00 2001 From: Golan Weiss Date: Mon, 7 Oct 2024 18:21:11 +0300 Subject: [PATCH] WLT-658 - GetPublicKey For NCW --- src/common/public_key_info.ts | 8 ++++++-- src/types.ts | 10 ++++++---- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/common/public_key_info.ts b/src/common/public_key_info.ts index 8d0aa42f..34bc0d41 100644 --- a/src/common/public_key_info.ts +++ b/src/common/public_key_info.ts @@ -7,9 +7,11 @@ export async function getPublicKeyInfoImpl(peerType: PeerType, args: PublicKeyIn let requestOptions: RequestOptions; if (peerType === PeerType.VAULT_ACCOUNT) { url = `/v1/vault/public_key_info`; - } else { + } else if (peerType === PeerType.END_USER_WALLET) { requestOptions = { ncw: { walletId } }; url = `/v1/ncw/${walletId}/public_key_info`; + } else { + throw new Error(`Unsupported peer type: ${peerType}`); } const query = queryString.stringify({ @@ -27,9 +29,11 @@ export async function getPublicKeyInfoByAccountAssetImpl(peerType: PeerType, arg let requestOptions: RequestOptions; if (peerType === PeerType.VAULT_ACCOUNT) { url = `/v1/vault/accounts/${(args as PublicKeyInfoForVaultAccountArgs).vaultAccountId}/${args.assetId}/${args.change}/${args.addressIndex}/public_key_info`; - } else { + } else if (peerType === PeerType.END_USER_WALLET) { requestOptions = { ncw: { walletId } }; url = `/v1/ncw/${walletId}/accounts/${(args as PublicKeyInfoByAccountAssetArgs).accountId}/${args.assetId}/${args.change}/${args.addressIndex}/public_key_info`; + } else { + throw new Error(`Unsupported peer type: ${peerType}`); } const query = queryString.stringify({ diff --git a/src/types.ts b/src/types.ts index e0b831a4..856b7306 100644 --- a/src/types.ts +++ b/src/types.ts @@ -1219,16 +1219,18 @@ export interface PublicKeyInfoArgs { compressed?: boolean; } -export interface PublicKeyInfoByAccountAssetArgs { +export interface BasePublicKeyInfoByAccountAssetArgs { assetId: string; - accountId: number; change: number; addressIndex: number; compressed?: boolean; } -export interface PublicKeyInfoForVaultAccountArgs - extends Omit { +export interface PublicKeyInfoByAccountAssetArgs extends BasePublicKeyInfoByAccountAssetArgs { + accountId: number; +} + +export interface PublicKeyInfoForVaultAccountArgs extends BasePublicKeyInfoByAccountAssetArgs { vaultAccountId: number; }