feat(js-client)!: Remove getter for secret key (#416)

* Remove secret key

* Node -> Relay

* Fix doc
This commit is contained in:
Akim 2024-01-12 15:25:45 +07:00 committed by GitHub
parent 4d90414190
commit 15f96dc5f7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 14 additions and 30 deletions

View File

@ -33,10 +33,6 @@ Here is an example using the JSDELIVR CDN:
```html ```html
<head> <head>
<title>Cool App</title> <title>Cool App</title>
<script
type="module"
src="https://cdn.jsdelivr.net/npm/@fluencelabs/js-client/dist/browser/index.min.js"
></script>
<script type="module"> <script type="module">
import { import {
Fluence, Fluence,

View File

@ -90,10 +90,6 @@ export class ClientPeer extends FluencePeer implements IFluenceClient {
); );
} }
getPeerSecretKey(): Uint8Array {
return this.keyPair.toEd25519PrivateKey();
}
connectionState: ConnectionState = "disconnected"; connectionState: ConnectionState = "disconnected";
connectionStateChangeHandler: (state: ConnectionState) => void = () => {}; connectionStateChangeHandler: (state: ConnectionState) => void = () => {};

View File

@ -21,29 +21,25 @@ import { z } from "zod";
*/ */
export type PeerIdB58 = string; export type PeerIdB58 = string;
const relaySchema = z.object({
peerId: z.string(),
multiaddr: z.string(),
});
/** /**
* Node of the Fluence network specified as a pair of node's multiaddr and it's peer id * Relay of the Fluence network specified as a pair of node's multiaddr and it's peer id
*/ */
export type Node = { export type Relay = z.infer<typeof relaySchema>;
peerId: PeerIdB58;
multiaddr: string;
};
export const relaySchema = z.union([ export const relayOptionsSchema = z.union([z.string(), relaySchema]);
z.string(),
z.object({
peerId: z.string(),
multiaddr: z.string(),
}),
]);
/** /**
* A node in Fluence network a client can connect to. * A relay in Fluence network a client can connect to.
* Can be in the form of: * Can be in the form of:
* - string: multiaddr in string format * - string: multiaddr in string format
* - Node: node structure, @see Node * - Relay: relay structure, @see Relay
*/ */
export type RelayOptions = z.infer<typeof relaySchema>; export type RelayOptions = z.infer<typeof relayOptionsSchema>;
/** /**
* Fluence Peer's key pair types * Fluence Peer's key pair types
@ -102,11 +98,6 @@ export interface IFluenceClient {
handler: (state: ConnectionState) => void, handler: (state: ConnectionState) => void,
): ConnectionState; ): ConnectionState;
/**
* Return peer's secret key as byte array.
*/
getPeerSecretKey(): Uint8Array;
/** /**
* Return peer's public key as a base58 string (multihash/CIDv0). * Return peer's public key as a base58 string (multihash/CIDv0).
*/ */

View File

@ -22,7 +22,7 @@ import {
configSchema, configSchema,
ConnectionState, ConnectionState,
RelayOptions, RelayOptions,
relaySchema, relayOptionsSchema,
} from "./clientPeer/types.js"; } from "./clientPeer/types.js";
import { callAquaFunction } from "./compilerSupport/callFunction.js"; import { callAquaFunction } from "./compilerSupport/callFunction.js";
import { registerService } from "./compilerSupport/registerService.js"; import { registerService } from "./compilerSupport/registerService.js";
@ -36,7 +36,7 @@ const createClient = async (
config: ClientConfig = {}, config: ClientConfig = {},
): Promise<ClientPeer> => { ): Promise<ClientPeer> => {
try { try {
relay = relaySchema.parse(relay); relay = relayOptionsSchema.parse(relay);
config = configSchema.parse(config); config = configSchema.parse(config);
} catch (e) { } catch (e) {
if (e instanceof ZodError) { if (e instanceof ZodError) {
@ -125,6 +125,7 @@ export type {
ClientConfig, ClientConfig,
IFluenceClient, IFluenceClient,
ConnectionState, ConnectionState,
Relay,
RelayOptions, RelayOptions,
KeyPairOptions, KeyPairOptions,
} from "./clientPeer/types.js"; } from "./clientPeer/types.js";