-
Notifications
You must be signed in to change notification settings - Fork 70
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* WLT-658 - GetPublicKey For NCW added two new functions for NCW GetPublicKey * WLT-658 - GetPublicKey For NCW code review fixes * WLT-658 - GetPublicKey For NCW * WLT-658 - GetPublicKey For NCW
- Loading branch information
Showing
6 changed files
with
100 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import { ApiClient } from "../api-client"; | ||
import { PeerType, PublicKeyInfoArgs, PublicKeyInfoByAccountAssetArgs, PublicKeyInfoForVaultAccountArgs, PublicKeyInformation, PublicKeyResponse, RequestOptions } from "../types"; | ||
import queryString from "query-string"; | ||
|
||
export async function getPublicKeyInfoImpl(peerType: PeerType, args: PublicKeyInfoArgs, apiClient: ApiClient, walletId?: string): Promise<PublicKeyInformation> { | ||
let url: string; | ||
let requestOptions: RequestOptions; | ||
if (peerType === PeerType.VAULT_ACCOUNT) { | ||
url = `/v1/vault/public_key_info`; | ||
} 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({ | ||
algorithm: args.algorithm, | ||
derivationPath: JSON.stringify(args.derivationPath), | ||
compressed: args.compressed, | ||
}); | ||
url += `?${query}`; | ||
|
||
return await apiClient.issueGetRequest(url, undefined, requestOptions); | ||
} | ||
|
||
export async function getPublicKeyInfoByAccountAssetImpl(peerType: PeerType, args: PublicKeyInfoForVaultAccountArgs | PublicKeyInfoByAccountAssetArgs, apiClient: ApiClient, walletId?: string): Promise<PublicKeyResponse> { | ||
let url: string; | ||
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 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({ | ||
compressed: args.compressed, | ||
}); | ||
url += `?${query}`; | ||
|
||
return await apiClient.issueGetRequest(url, undefined, requestOptions); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters