Skip to content

Commit

Permalink
0.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
penpenpng committed Jun 25, 2023
0 parents commit 9dacb25
Show file tree
Hide file tree
Showing 10 changed files with 1,882 additions and 0 deletions.
23 changes: 23 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"env": {
"browser": true,
"es2021": true,
"node": true
},
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/recommended",
"prettier"
],
"overrides": [],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": "latest",
"sourceType": "module"
},
"plugins": ["@typescript-eslint"],
"rules": {
"@typescript-eslint/no-namespace": "off"
},
"ignorePatterns": ["./*.json", "node_modules"]
}
26 changes: 26 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: lint

on:
push:
branches: [main]
pull_request:
branches: [main]

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: ${{ vars.NODE_VERSION }}
registry-url: https://registry.npmjs.org
- name: cache node_modules
id: node_modules_cache_id
uses: actions/cache@v2
with:
path: |
node_modules
key: node-v${{ vars.NODE_VERSION }}-deps-${{ hashFiles(format('{0}{1}', github.workspace, '/package-lock.json')) }}
- run: npm ci
- run: npm run lint
27 changes: 27 additions & 0 deletions .github/workflows/npm-publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: npm publish

on:
release:
types: [created]

jobs:
npm-publish:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: ${{ vars.NODE_VERSION }}
registry-url: https://registry.npmjs.org
- name: cache node_modules
id: node_modules_cache_id
uses: actions/cache@v2
with:
path: |
node_modules
key: node-v${{ vars.NODE_VERSION }}-deps-${{ hashFiles(format('{0}{1}', github.workspace, '/package-lock.json')) }}
- run: npm ci
- run: npm run lint
- run: npx -y can-npm-publish && npm publish
env:
NODE_AUTH_TOKEN: ${{secrets.NODE_AUTH_TOKEN}}
23 changes: 23 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
lerna-debug.log*

node_modules
dist
types

# Editor directories and files
.vscode/*
!.vscode/extensions.json
.idea
.DS_Store
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2023 penpenpng

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# nostr-typedef
220 changes: 220 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,220 @@
export interface Event<K = number> {
id: string;
sig: string;
kind: K;
tags: string[][];
pubkey: string;
content: string;
created_at: number;
}

export interface UnsignedEvent<K = number> {
kind: K;
tags: string[][];
pubkey: string;
content: string;
created_at: number;
}

export interface EventParameters<K = number> {
id?: string;
sig?: string;
kind: K;
tags?: string[][];
pubkey?: string;
content: string;
created_at?: number;
}

export enum Kind {
Metadata = 0,
Text = 1,
RecommendRelay = 2,
Contacts = 3,
EncryptedDirectMessage = 4,
EventDeletion = 5,
Repost = 6,
Reaction = 7,
BadgeAward = 8,
GenericRepost = 16,
ChannelCreation = 40,
ChannelMetadata = 41,
ChannelMessage = 42,
ChannelHideMessage = 43,
ChannelMuteUser = 44,
Blank = 255,
FileMetadata = 1063,
Reporting = 1984,
Label = 1985,
ZapRequest = 9734,
Zap = 9735,
MuteList = 10000,
PinList = 10001,
RelayListMetadata = 10002,
WalletInfo = 13194,
ClientAuthentication = 22242,
WalletRequest = 23194,
WalletResponse = 23195,
NostrConnect = 24133,
HttpAuth = 27235,
CategorizedPeopleList = 30000,
GategorizedBookmarkList = 30001,
ProfileBadges = 30008,
BadgeDefinition = 30009,
CreateOrUpdateStall = 30017,
CreateOrUpdateProduct = 30018,
LongFormContent = 30023,
ApplicationSpecificData = 30078,
HandlerRecommendation = 31989,
HandlerInformation = 31990,
}

type Chars<S extends string> = S extends `${infer Head}${infer Tail}`
? Uppercase<Head> | Lowercase<Head> | Chars<Tail>
: never;
// cf. NIP-12
export type TagName = `#${Chars<"abcdefghijklmnopqrstuvwxyz">}`;

export type Filter = {
ids?: string[];
kinds?: number[];
authors?: string[];
since?: number;
until?: number;
limit?: number;
} & {
[key in TagName]?: string[];
};

interface CountResponse {
count: number;
}

export namespace ToRelayMessage {
export type Any = AUTH | CLOSE | COUNT | EVENT | REQ;
export type AUTH = [type: "AUTH", event: Event<Kind.ClientAuthentication>];
export type CLOSE = [type: "CLOSE", subId: string];
export type COUNT = [type: "COUNT", subId: string, ...filters: Filter[]];
export type EVENT = [type: "EVENT", event: Event];
export type REQ = [type: "REQ", subId: string, ...filters: Filter[]];
}

export namespace ToClientMessage {
export type Any = AUTH | COUNT | EOSE | EVENT | NOTICE | OK;
export type Sub = EVENT | EOSE;
export type AUTH = [type: "AUTH", challengeMessage: string];
export type COUNT = [type: "COUNT", subId: string, count: CountResponse];
export type EOSE = [type: "EOSE", subId: string];
export type EVENT = [type: "EVENT", subId: string, event: Event];
export type NOTICE = [type: "NOTICE", message: string];
export type OK = [
type: "OK",
eventId: string,
succeeded: boolean,
message?: string
];
}

export namespace Nip07 {
export interface Nostr {
getPublicKey: () => Promise<string>;
signEvent: (event: {
kind: number;
tags: string[][];
content: string;
created_at: number;
}) => Promise<{
id: string;
sig: string;
kind: number;
tags: string[][];
pubkey: string;
content: string;
created_at: number;
}>;
getRelays?: () => Promise<GetRelayResult>;
nip04?: Nip04Crypto;
}

export interface GetRelayResult {
[url: string]: { read: boolean; write: boolean };
}

export interface Nip04Crypto {
encrypt: (pubkey: string, plaintext: string) => string;
decrypt: (pubkey: string, ciphertext: string) => string;
}
}

export namespace Nip11 {
export interface RelayInfo {
/** https://github.com/nostr-protocol/nips/blob/master/11.md#name */
name?: string;
/** https://github.com/nostr-protocol/nips/blob/master/11.md#description */
description?: string;
/** https://github.com/nostr-protocol/nips/blob/master/11.md#pubkey */
pubkey?: string;
/** https://github.com/nostr-protocol/nips/blob/master/11.md#contact */
contact?: string;
/** https://github.com/nostr-protocol/nips/blob/master/11.md#supported-nips */
supported_nips?: number[];
/** https://github.com/nostr-protocol/nips/blob/master/11.md#software */
software?: string;
/** https://github.com/nostr-protocol/nips/blob/master/11.md#version */
version?: string;
/** https://github.com/nostr-protocol/nips/blob/master/11.md#server-limitations */
limitation?: ServerLimitations;
/** https://github.com/nostr-protocol/nips/blob/master/11.md#event-retention */
retention?: EventRetention[];
/** https://github.com/nostr-protocol/nips/blob/master/11.md#content-limitations */
relay_countries?: string[];
/** https://github.com/nostr-protocol/nips/blob/master/11.md#community-preferences */
language_tags?: string[];
/** https://github.com/nostr-protocol/nips/blob/master/11.md#community-preferences */
tags?: string[];
/** https://github.com/nostr-protocol/nips/blob/master/11.md#community-preferences */
posting_policy?: string;
/** https://github.com/nostr-protocol/nips/blob/master/11.md#pay-to-relay */
payments_url?: string;
/** https://github.com/nostr-protocol/nips/blob/master/11.md#pay-to-relay */
fees?: RelayFees;
/** https://github.com/nostr-protocol/nips/blob/master/11.md#icon */
icon?: string;
[key: string]: unknown;
}

export interface ServerLimitations {
max_message_length?: number;
max_subscriptions?: number;
max_filters?: number;
max_limit?: number;
max_subid_length?: number;
min_prefix?: number;
max_event_tags?: number;
max_content_length?: number;
min_pow_difficulty?: number;
auth_required?: boolean;
payment_required?: boolean;
}

export interface EventRetention {
kinds?: (number | [start: number, end: number])[];
time?: number | null;
count?: number;
}

export interface RelayFees {
admission?: RelayFeeAmount[];
subscription?: RelayFeeAmount[];
publication?: RelayFeeAmount[];
}

export interface RelayFeeAmount {
amount?: number;
unit?: string;
period?: number;
kinds?: number[];
}
}

export {};
Loading

0 comments on commit 9dacb25

Please sign in to comment.