Add method to get address from private key

This commit is contained in:
IshaVenikar 2024-10-24 19:07:02 +05:30
parent a1597900f6
commit 7383d5c36d
6 changed files with 31 additions and 1 deletions

View File

@ -5,7 +5,7 @@ import { Octokit } from 'octokit';
import { inc as semverInc } from 'semver';
import { DeepPartial } from 'typeorm';
import { Registry as LaconicRegistry, getGasPrice, parseGasAndFees } from '@cerc-io/registry-sdk';
import { Account, Registry as LaconicRegistry, getGasPrice, parseGasAndFees } from '@cerc-io/registry-sdk';
import { RegistryConfig } from './config';
import {
@ -498,6 +498,13 @@ export class Registry {
);
}
async getAddress(): Promise<any> {
const account = new Account(Buffer.from(this.registryConfig.privateKey, 'hex'));
await account.init();
return account.address;
}
getLrn(appName: string): string {
assert(this.registryConfig.authority, "Authority doesn't exist");
return `lrn://${this.registryConfig.authority}/applications/${appName}`;

View File

@ -80,6 +80,10 @@ export const createResolvers = async (service: Service): Promise<any> => {
deployers: async (_: any, __: any, context: any) => {
return service.getDeployers();
},
address: async (_: any, __: any, context: any) => {
return service.getAddress();
},
},
// TODO: Return error in GQL response

View File

@ -264,6 +264,7 @@ type Query {
getAuctionData(auctionId: String!): Auction!
domains(projectId: String!, filter: FilterDomainsInput): [Domain]
deployers: [Deployer]
address: String!
}
type Mutation {

View File

@ -1401,4 +1401,8 @@ export class Service {
return deployers;
}
async getAddress(): Promise<any> {
return this.laconicRegistry.getAddress();
}
}

View File

@ -432,4 +432,12 @@ export class GQLClient {
return data;
}
async getAddress(): Promise<string> {
const { data } = await this.client.query({
query: queries.getAddress,
});
return data;
}
}

View File

@ -323,3 +323,9 @@ query {
}
}
`;
export const getAddress = gql`
query {
address
}
`;