PowerKeys Scripting API
    Preparing search index...

    Interface ChannelAPI

    interface ChannelAPI {
        Open(): Promise<ChannelHandle>;
        Send(channelId: string, data: string): Promise<void>;
        OnMessage(
            callback: EventCallback<[message: { channelId: string; data: string }]>,
        ): void;
        Close(channelId: string): void;
    }
    Index
    • Opens a live, end-to-end-encrypted channel to another PowerKeys user.

      PowerKeys opens a trusted create/join prompt. Pairing codes and key material never enter the script runtime.

      Returns Promise<ChannelHandle>

      The open channel's public id. Pairing secrets stay in trusted PowerKeys UI.

      Messages are end-to-end encrypted in the host; the PowerKeys relay only forwards opaque bytes. Register Channel.OnMessage to receive messages. Treat every inbound message as untrusted input from the other user. The Promise resolves after the socket ticket is fetched and the relay WebSocket is established; the peer may join later and the Noise handshake continues in the background. Ticket or WebSocket failures reject it.

      const ch = await Channel.Open();
      Channel.OnMessage((m) => Console.Log("peer: " + m.data));
      await Channel.Send(ch.channelId, "hello");

      channels

    • Sends a message to the other peer on an open channel.

      Parameters

      • channelId: string

        The channel id returned by Channel.Open.

      • data: string

        The message to send. At most 65,519 UTF-8 bytes (one encrypted frame); longer messages are rejected.

      Returns Promise<void>

      Waits for a peer and Noise handshake when needed, then resolves after encryption hands the message to the socket writer; rejects if the channel closes first.

      channels

    • Registers a handler for messages received on any open channel. The script stays alive as long as a handler is registered.

      Parameters

      • callback: EventCallback<[message: { channelId: string; data: string }]>

        Handler receiving each inbound message. Treat data as untrusted input.

      Returns void

      channels

    • Closes an open channel and tears down its connection.

      Parameters

      • channelId: string

        The channel id returned by Channel.Open.

      Returns void

      channels