Skip to content

Commit

Permalink
Improve signEvent typing
Browse files Browse the repository at this point in the history
  • Loading branch information
penpenpng committed Dec 20, 2023
1 parent 25d1d8d commit 6b3e3bc
Showing 1 changed file with 17 additions and 8 deletions.
25 changes: 17 additions & 8 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -546,15 +546,19 @@ export namespace ToClientMessage {
/** EVENT message. See also [NIP-01](https://github.com/nostr-protocol/nips/blob/master/01.md). */
export type EVENT = [type: "EVENT", subId: string, event: Event];
/** CLOSED message. See also [NIP-01](https://github.com/nostr-protocol/nips/blob/master/01.md). */
export type CLOSED = [type: "CLOSED", subId: string, message: string];
export type CLOSED = [
type: "CLOSED",
subId: string,
message: MachineReadablePrefixedMessage | string
];
/** NOTICE message. See also [NIP-01](https://github.com/nostr-protocol/nips/blob/master/01.md). */
export type NOTICE = [type: "NOTICE", message: string];
/** OK message. See also [NIP-20](https://github.com/nostr-protocol/nips/blob/master/20.md). */
export type OK = [
type: "OK",
eventId: string,
succeeded: boolean,
message: OkMessageAnnotation | string
message: MachineReadablePrefixedMessage | string
];
}

Expand All @@ -563,27 +567,32 @@ export interface CountResponse {
}

/**
* See also [NIP-01](https://github.com/nostr-protocol/nips/blob/master/01.md#from-relay-to-client-sending-events-and-notices).
* See also [NIP-01](https://github.com/nostr-protocol/nips/blob/master/01.md#from-relay-to-client-sending-events-and-notices) and [NIP-42](https://github.com/nostr-protocol/nips/blob/master/42.md).
*/
export type MachineReadablePrefix =
| "duplicate"
| "pow"
| "blocked"
| "rate-limited"
| "invalid"
| "error";
| "error"
| "auth-required"
| "restricted";

export type OkMessageAnnotation = `${MachineReadablePrefix}:${string}`;
export type MachineReadablePrefixedMessage =
`${MachineReadablePrefix}:${string}`;
/** @deprecated Renamed. Use `MachineReadablePrefixedMessage` instead */
export type OkMessageAnnotation = MachineReadablePrefixedMessage;

export namespace Nip07 {
export interface Nostr {
getPublicKey: () => Promise<string>;
signEvent: (event: {
kind: number;
signEvent: <K extends number>(event: {
kind: K;
tags: Tag.Any[];
content: string;
created_at: number;
}) => Promise<Event>;
}) => Promise<Event<K>>;
getRelays?: () => Promise<GetRelayResult>;
nip04?: Nip04Crypto;
}
Expand Down

0 comments on commit 6b3e3bc

Please sign in to comment.