commit b9af45317927dddd4b6f8f82d211e55afcb5dbd3
parent b8797cc75a8af8f5d0486d695ae74bd25cd8794a
Author: triesap <137732411+triesap@users.noreply.github.com>
Date: Fri, 30 Aug 2024 19:55:51 +0000
client: add iclientnostr
Diffstat:
5 files changed, 38 insertions(+), 0 deletions(-)
diff --git a/client/package.json b/client/package.json
@@ -21,6 +21,7 @@
"@capacitor/share": "^6.0.0",
"@capacitor/splash-screen": "^6.0.0",
"@capacitor/status-bar": "^6.0.0",
+ "@nostr-dev-kit/ndk": "^2.7.1",
"@radroots/capacitor-bluetooth-le": "workspace:*",
"@radroots/capacitor-date-picker": "workspace:*",
"@radroots/capacitor-native-settings": "workspace:*",
diff --git a/client/src/capacitor/index.ts b/client/src/capacitor/index.ts
@@ -1,5 +1,6 @@
import { Capacitor } from "@capacitor/core";
+import { ClientNostr } from "../nostr";
import type { IClient, IClientBluetoothLe, IClientBrowser, IClientCamera, IClientDatePicker, IClientDevice, IClientDialog, IClientGeolocation, IClientHaptics, IClientHttp, IClientKeystore, IClientNetwork, IClientPlatform, IClientPreferences, IClientShare, IClientWifi, IClientWindow } from "../types";
import { parse_platform } from "../utils";
import { CapacitorClientBluetoothLe } from "./bluetooth-le";
@@ -21,6 +22,7 @@ import { CapacitorClientWifi } from "./wifi";
import { CapacitorClientWindow } from "./window";
export class ClientCapacitor implements IClient {
+ private _nostr: ClientNostr = new ClientNostr();
private _platform: IClientPlatform = parse_platform(Capacitor.getPlatform());
private _keystore: IClientKeystore = new CapacitorClientKeystore();
private _device: IClientDevice = new CapacitorClientDevice();
@@ -40,6 +42,10 @@ export class ClientCapacitor implements IClient {
private _db: CapacitorClientSQLite = new CapacitorClientSQLite();
private _settings: CapacitorClientSettings = new CapacitorClientSettings();
+ public get nostr() {
+ return this._nostr;
+ }
+
public get platform() {
return this._platform;
}
diff --git a/client/src/nostr/events.ts b/client/src/nostr/events.ts
@@ -0,0 +1,9 @@
+import { type NDKEvent } from "@nostr-dev-kit/ndk";
+import type { IClientNostrEvents } from "../types";
+
+export class ClientNostrEvents implements IClientNostrEvents {
+ public first_tag_value(event: NDKEvent, tag_name: string): string {
+ const tag = event.getMatchingTags(tag_name)[0];
+ return tag ? tag[1] : "";
+ }
+}
+\ No newline at end of file
diff --git a/client/src/nostr/index.ts b/client/src/nostr/index.ts
@@ -0,0 +1,10 @@
+import type { IClientNostr } from "../types";
+import { ClientNostrEvents } from "./events";
+
+export class ClientNostr implements IClientNostr {
+ private _ev: ClientNostrEvents = new ClientNostrEvents();
+
+ public get ev() {
+ return this._ev;
+ }
+}
+\ No newline at end of file
diff --git a/client/src/types.ts b/client/src/types.ts
@@ -1,10 +1,12 @@
import { type BatteryInfo, type DeviceInfo } from '@capacitor/device';
+import { type NDKEvent } from "@nostr-dev-kit/ndk";
import { type ScanResult } from '@radroots/capacitor-bluetooth-le';
import { IOSSettings, type AndroidSettings } from '@radroots/capacitor-native-settings';
import { type ConnectToWifiResult, type GetCurrentWifiResult, type PermissionStatus, type ScanWifiResult } from '@radroots/capacitor-wifi';
import { type ErrorResponse } from '@radroots/utils';
export type IClient = {
+ nostr: IClientNostr;
platform: IClientPlatform;
keystore: IClientKeystore;
device: IClientDevice;
@@ -23,6 +25,10 @@ export type IClient = {
settings: IClientSettings;
};
+export type IClientNostr = {
+ ev: IClientNostrEvents;
+};
+
export type IClientPlatform = `androiď` | `ios` | `web`;
export type IClientKeystore = {
@@ -250,4 +256,8 @@ export type IClientSettingsOpen = IClientSettingsOpenAndroid | IClientSettingsOp
export type IClientSettings = {
open(opts: IClientSettingsOpen): Promise<boolean>;
+};
+
+export type IClientNostrEvents = {
+ first_tag_value(event: NDKEvent, tag_name: string): string;
};
\ No newline at end of file