feat: Add getRelayPeerId method for IFluenceClient (#260)

This commit is contained in:
Pavel
2023-02-16 15:33:03 +03:00
committed by GitHub
parent 0e795cb0fc
commit a10278afaa
3 changed files with 14 additions and 2 deletions

View File

@@ -36,6 +36,9 @@ export const main = async () => {
console.log('connected'); console.log('connected');
const relayPeerId = (await Fluence.getClient()).getRelayPeerId();
console.log('relay:', relayPeerId);
await registerHelloWorld({ await registerHelloWorld({
hello(str) { hello(str) {
return 'Hello, ' + str + '!'; return 'Hello, ' + str + '!';

View File

@@ -141,15 +141,20 @@ export interface IFluenceClient {
onConnectionStateChange(handler: (state: ConnectionState) => void): ConnectionState; onConnectionStateChange(handler: (state: ConnectionState) => void): ConnectionState;
/** /**
* Return peers secret key as byte array. * Return peer's secret key as byte array.
*/ */
getPeerSecretKey(): Uint8Array; getPeerSecretKey(): Uint8Array;
/** /**
* Return peers public key as a base58 string (multihash/CIDv0). * Return peer's public key as a base58 string (multihash/CIDv0).
*/ */
getPeerId(): string; getPeerId(): string;
/**
* Return relay's public key as a base58 string (multihash/CIDv0).
*/
getRelayPeerId(): string;
// TODO: come up with a working interface for // TODO: come up with a working interface for
// - particle creation // - particle creation
// - particle initialization // - particle initialization

View File

@@ -142,6 +142,10 @@ export class FluencePeer implements IFluenceClient {
return this.getStatus().peerId!; return this.getStatus().peerId!;
} }
getRelayPeerId(): string {
return this.getStatus().relayPeerId!;
}
getPeerSecretKey(): Uint8Array { getPeerSecretKey(): Uint8Array {
if (!this._keyPair) { if (!this._keyPair) {
throw new Error("Can't get key pair: peer is not initialized"); throw new Error("Can't get key pair: peer is not initialized");