diff --git a/src/golem-network/golem-network.test.ts b/src/golem-network/golem-network.test.ts index 09f6715fb..112144c5c 100644 --- a/src/golem-network/golem-network.test.ts +++ b/src/golem-network/golem-network.test.ts @@ -25,6 +25,13 @@ const order: MarketOrderSpec = Object.freeze({ }, }, } as const); + +const identity = { + identity: "0x0123456789", + role: "test-role", + name: "test-name", +}; + const mockMarket = mock(MarketModuleImpl); const mockPayment = mock(PaymentModuleImpl); const mockActivity = mock(ActivityModuleImpl); @@ -54,6 +61,7 @@ afterEach(() => { beforeEach(() => { when(mockStorageProvider.close()).thenResolve(); when(mockYagna.disconnect()).thenResolve(); + when(mockYagna.connect()).thenResolve(identity); }); function getGolemNetwork() { diff --git a/src/golem-network/golem-network.ts b/src/golem-network/golem-network.ts index acdb784db..364c436f4 100644 --- a/src/golem-network/golem-network.ts +++ b/src/golem-network/golem-network.ts @@ -40,6 +40,7 @@ import { DataTransferProtocol } from "../shared/types"; import { NetworkApiAdapter } from "../shared/yagna/adapters/network-api-adapter"; import { IProposalRepository } from "../market/proposal"; import { Subscription } from "rxjs"; +import { GolemUserError } from "../shared/error/golem-error"; /** * Instance of an object or a factory function that you can call `new` on. @@ -226,6 +227,8 @@ export class GolemNetwork { */ private cleanupTasks: (() => Promise | void)[] = []; + private identity?: string; + constructor(options: Partial = {}) { const optDefaults: GolemNetworkOptions = { dataTransferProtocol: isNode ? "gftp" : "ws", @@ -321,7 +324,7 @@ export class GolemNetwork { */ async connect() { try { - await this.yagna.connect(); + this.identity = (await this.yagna.connect()).identity; await this.services.paymentApi.connect(); await this.storageProvider.init(); this.events.emit("connected"); @@ -632,6 +635,17 @@ export class GolemNetwork { return this.hasConnection; } + /** + * Yagna Node Id used by the requester. + * It depends on the Yagny Api Key used and reflects the user's eth wallet address. + */ + getIdentity(): string { + if (!this.isConnected() || !this.identity) { + throw new GolemUserError("To obtain an identity, you must first connect to the Golem Network."); + } + return this.identity; + } + /** * Creates a new logical network within the Golem VPN infrastructure. * Allows communication between network nodes using standard network mechanisms,