mirror of
https://github.com/Qortal/Qortal-Hub.git
synced 2025-11-16 12:57:11 +00:00
added get public key from address message
This commit is contained in:
@@ -13,6 +13,7 @@ import {
|
||||
handleNamesMessage,
|
||||
handlePrimaryNameMessage,
|
||||
handleProcessTransactionResponseMessage,
|
||||
handlePublicKeyMessage,
|
||||
handleUnitFee,
|
||||
} from '../messages/handlers';
|
||||
import { getRandomClient } from '../peerService';
|
||||
@@ -35,6 +36,7 @@ import {
|
||||
createGetNamesPayload,
|
||||
createGetOwnerGroupsPayload,
|
||||
createGetPrimaryNamePayload,
|
||||
createGetPublickeyFromAddressPayload,
|
||||
createGetUnitFeePayload,
|
||||
createProcessTransactionMessagePayload,
|
||||
createSearchNamesPayload,
|
||||
@@ -260,6 +262,18 @@ export async function getLastReference(address: string): Promise<any> {
|
||||
return handleLastReference(res);
|
||||
}
|
||||
|
||||
export async function getPublickeyFromAddress(address: string): Promise<any> {
|
||||
const client = getRandomClient();
|
||||
if (!client) throw new Error('No available peers');
|
||||
|
||||
const res: Buffer = await client.sendRequest(
|
||||
MessageType.GET_PUBLIC_KEY_FROM_ADDRESS,
|
||||
createGetPublickeyFromAddressPayload(address)
|
||||
);
|
||||
|
||||
return handlePublicKeyMessage(res);
|
||||
}
|
||||
|
||||
export async function getPrimaryName(address: string): Promise<any> {
|
||||
const client = getRandomClient();
|
||||
if (!client) throw new Error('No available peers');
|
||||
|
||||
@@ -19,6 +19,7 @@ import {
|
||||
getNamesForSale,
|
||||
getOwnerGroups,
|
||||
getPrimaryName,
|
||||
getPublickeyFromAddress,
|
||||
getSearchNames,
|
||||
getUnitFee,
|
||||
processTransaction,
|
||||
@@ -215,6 +216,16 @@ export async function createHttpServer() {
|
||||
}
|
||||
});
|
||||
|
||||
app.get('/addresses/publickey/:address', async (req, res) => {
|
||||
try {
|
||||
const address = req.params.address;
|
||||
const publickey = await getPublickeyFromAddress(address);
|
||||
res.type('text').send(publickey);
|
||||
} catch (err: any) {
|
||||
res.status(500).type('text').send(`Error: ${err.message}`);
|
||||
}
|
||||
});
|
||||
|
||||
app.get('/names', async (req, res) => {
|
||||
try {
|
||||
console.log('hello');
|
||||
|
||||
@@ -636,3 +636,15 @@ export function handleGroupMembersMessage(buffer) {
|
||||
members,
|
||||
};
|
||||
}
|
||||
|
||||
export function handlePublicKeyMessage(buffer: Buffer) {
|
||||
if (buffer.length !== 32) {
|
||||
throw new Error(
|
||||
`Invalid public key message length: expected 32, got ${buffer.length}`
|
||||
);
|
||||
}
|
||||
|
||||
const publicKeyBytes = buffer.subarray(0, 32);
|
||||
|
||||
return bs58.encode(publicKeyBytes);
|
||||
}
|
||||
|
||||
@@ -44,4 +44,7 @@ export enum MessageType {
|
||||
GROUP_MEMBERS = 321,
|
||||
GET_GROUP_MEMBERS = 322,
|
||||
GET_OWNER_GROUPS = 323,
|
||||
|
||||
PUBLIC_KEY = 324,
|
||||
GET_PUBLIC_KEY_FROM_ADDRESS = 325,
|
||||
}
|
||||
|
||||
@@ -309,6 +309,18 @@ export function createGetLastReferencePayload(address: string): Buffer {
|
||||
return Buffer.from(addressBytes);
|
||||
}
|
||||
|
||||
export function createGetPublickeyFromAddressPayload(address: string): Buffer {
|
||||
const addressBytes = bs58.decode(address);
|
||||
|
||||
if (addressBytes.length !== ADDRESS_LENGTH) {
|
||||
throw new Error(
|
||||
`Invalid address length. Expected ${ADDRESS_LENGTH}, got ${addressBytes.length}`
|
||||
);
|
||||
}
|
||||
|
||||
return Buffer.from(addressBytes);
|
||||
}
|
||||
|
||||
export function createGetPrimaryNamePayload(address: string): Buffer {
|
||||
const addressBytes = bs58.decode(address);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user