signEvent

Method

async function signEvent(event: UnsignedEvent): Event 

Params

  • eventrequired object

    • kindrequired number

    • contentrequired string

    • tagsrequired Array<Array<string>>

    • created_atrequired number

export type UnsignedEvent = {
  kind: EventKind;
  content: string;
  tags: string[][];
  created_at: number;
};

export enum EventKind {
  Metadata = 0,
  Text = 1,
  RelayRec = 2,
  Contacts = 3,
  DM = 4,
  Deleted = 5,
}

Response

takes an event object, adds id, pubkey and sig and returns it

Result

export type Event = {
  id: string;
  kind: EventKind;
  pubkey: string;
  content: string;
  tags: string[][];
  created_at: number;
  sig: string;
};

Example

const event = {
  created_at: 1700000000,
  kind: 1,
  content: "OneKey 🚀",
  tags: [],
};
const provider = (window.$onekey && window.$onekey.nostr) || window.nostr;

const signedEvent = await provider.signEvent(event);

Demo

Last updated