@unicitylabs/nostr-js-sdk 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +290 -0
- package/dist/browser/index.js +8444 -0
- package/dist/browser/index.js.map +1 -0
- package/dist/browser/index.min.js +12 -0
- package/dist/browser/index.min.js.map +1 -0
- package/dist/browser/index.umd.js +8524 -0
- package/dist/browser/index.umd.js.map +1 -0
- package/dist/browser/index.umd.min.js +12 -0
- package/dist/browser/index.umd.min.js.map +1 -0
- package/dist/cjs/NostrKeyManager.js +265 -0
- package/dist/cjs/NostrKeyManager.js.map +1 -0
- package/dist/cjs/client/NostrClient.js +518 -0
- package/dist/cjs/client/NostrClient.js.map +1 -0
- package/dist/cjs/client/NostrEventListener.js +31 -0
- package/dist/cjs/client/NostrEventListener.js.map +1 -0
- package/dist/cjs/client/WebSocketAdapter.js +90 -0
- package/dist/cjs/client/WebSocketAdapter.js.map +1 -0
- package/dist/cjs/client/index.js +18 -0
- package/dist/cjs/client/index.js.map +1 -0
- package/dist/cjs/crypto/bech32.js +201 -0
- package/dist/cjs/crypto/bech32.js.map +1 -0
- package/dist/cjs/crypto/index.js +49 -0
- package/dist/cjs/crypto/index.js.map +1 -0
- package/dist/cjs/crypto/nip04.js +327 -0
- package/dist/cjs/crypto/nip04.js.map +1 -0
- package/dist/cjs/crypto/schnorr.js +101 -0
- package/dist/cjs/crypto/schnorr.js.map +1 -0
- package/dist/cjs/index.js +57 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/cjs/nametag/NametagBinding.js +196 -0
- package/dist/cjs/nametag/NametagBinding.js.map +1 -0
- package/dist/cjs/nametag/NametagUtils.js +156 -0
- package/dist/cjs/nametag/NametagUtils.js.map +1 -0
- package/dist/cjs/nametag/index.js +47 -0
- package/dist/cjs/nametag/index.js.map +1 -0
- package/dist/cjs/protocol/Event.js +209 -0
- package/dist/cjs/protocol/Event.js.map +1 -0
- package/dist/cjs/protocol/EventKinds.js +126 -0
- package/dist/cjs/protocol/EventKinds.js.map +1 -0
- package/dist/cjs/protocol/Filter.js +202 -0
- package/dist/cjs/protocol/Filter.js.map +1 -0
- package/dist/cjs/protocol/index.js +50 -0
- package/dist/cjs/protocol/index.js.map +1 -0
- package/dist/cjs/token/TokenTransferProtocol.js +196 -0
- package/dist/cjs/token/TokenTransferProtocol.js.map +1 -0
- package/dist/cjs/token/index.js +45 -0
- package/dist/cjs/token/index.js.map +1 -0
- package/dist/esm/NostrKeyManager.js +228 -0
- package/dist/esm/NostrKeyManager.js.map +1 -0
- package/dist/esm/client/NostrClient.js +481 -0
- package/dist/esm/client/NostrClient.js.map +1 -0
- package/dist/esm/client/NostrEventListener.js +27 -0
- package/dist/esm/client/NostrEventListener.js.map +1 -0
- package/dist/esm/client/WebSocketAdapter.js +52 -0
- package/dist/esm/client/WebSocketAdapter.js.map +1 -0
- package/dist/esm/client/index.js +7 -0
- package/dist/esm/client/index.js.map +1 -0
- package/dist/esm/crypto/bech32.js +193 -0
- package/dist/esm/crypto/bech32.js.map +1 -0
- package/dist/esm/crypto/index.js +10 -0
- package/dist/esm/crypto/index.js.map +1 -0
- package/dist/esm/crypto/nip04.js +286 -0
- package/dist/esm/crypto/nip04.js.map +1 -0
- package/dist/esm/crypto/schnorr.js +93 -0
- package/dist/esm/crypto/schnorr.js.map +1 -0
- package/dist/esm/index.js +32 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/nametag/NametagBinding.js +155 -0
- package/dist/esm/nametag/NametagBinding.js.map +1 -0
- package/dist/esm/nametag/NametagUtils.js +149 -0
- package/dist/esm/nametag/NametagUtils.js.map +1 -0
- package/dist/esm/nametag/index.js +8 -0
- package/dist/esm/nametag/index.js.map +1 -0
- package/dist/esm/protocol/Event.js +172 -0
- package/dist/esm/protocol/Event.js.map +1 -0
- package/dist/esm/protocol/EventKinds.js +119 -0
- package/dist/esm/protocol/EventKinds.js.map +1 -0
- package/dist/esm/protocol/Filter.js +197 -0
- package/dist/esm/protocol/Filter.js.map +1 -0
- package/dist/esm/protocol/index.js +8 -0
- package/dist/esm/protocol/index.js.map +1 -0
- package/dist/esm/token/TokenTransferProtocol.js +154 -0
- package/dist/esm/token/TokenTransferProtocol.js.map +1 -0
- package/dist/esm/token/index.js +6 -0
- package/dist/esm/token/index.js.map +1 -0
- package/dist/types/NostrKeyManager.d.ts +150 -0
- package/dist/types/NostrKeyManager.d.ts.map +1 -0
- package/dist/types/client/NostrClient.d.ts +154 -0
- package/dist/types/client/NostrClient.d.ts.map +1 -0
- package/dist/types/client/NostrEventListener.d.ts +40 -0
- package/dist/types/client/NostrEventListener.d.ts.map +1 -0
- package/dist/types/client/WebSocketAdapter.d.ts +55 -0
- package/dist/types/client/WebSocketAdapter.d.ts.map +1 -0
- package/dist/types/client/index.d.ts +9 -0
- package/dist/types/client/index.d.ts.map +1 -0
- package/dist/types/crypto/bech32.d.ts +51 -0
- package/dist/types/crypto/bech32.d.ts.map +1 -0
- package/dist/types/crypto/index.d.ts +10 -0
- package/dist/types/crypto/index.d.ts.map +1 -0
- package/dist/types/crypto/nip04.d.ts +56 -0
- package/dist/types/crypto/nip04.d.ts.map +1 -0
- package/dist/types/crypto/schnorr.d.ts +47 -0
- package/dist/types/crypto/schnorr.d.ts.map +1 -0
- package/dist/types/index.d.ts +31 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/nametag/NametagBinding.d.ts +68 -0
- package/dist/types/nametag/NametagBinding.d.ts.map +1 -0
- package/dist/types/nametag/NametagUtils.d.ts +44 -0
- package/dist/types/nametag/NametagUtils.d.ts.map +1 -0
- package/dist/types/nametag/index.d.ts +8 -0
- package/dist/types/nametag/index.d.ts.map +1 -0
- package/dist/types/protocol/Event.d.ts +112 -0
- package/dist/types/protocol/Event.d.ts.map +1 -0
- package/dist/types/protocol/EventKinds.d.ts +62 -0
- package/dist/types/protocol/EventKinds.d.ts.map +1 -0
- package/dist/types/protocol/Filter.d.ts +146 -0
- package/dist/types/protocol/Filter.d.ts.map +1 -0
- package/dist/types/protocol/index.d.ts +10 -0
- package/dist/types/protocol/index.d.ts.map +1 -0
- package/dist/types/token/TokenTransferProtocol.d.ts +67 -0
- package/dist/types/token/TokenTransferProtocol.d.ts.map +1 -0
- package/dist/types/token/index.d.ts +6 -0
- package/dist/types/token/index.d.ts.map +1 -0
- package/package.json +89 -0
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* NostrClient - Main entry point for Nostr protocol operations.
|
|
3
|
+
* Handles relay connections, event publishing, and subscriptions.
|
|
4
|
+
*/
|
|
5
|
+
import { NostrKeyManager } from '../NostrKeyManager.js';
|
|
6
|
+
import { Event, UnsignedEventData } from '../protocol/Event.js';
|
|
7
|
+
import { Filter } from '../protocol/Filter.js';
|
|
8
|
+
import { NostrEventListener } from './NostrEventListener.js';
|
|
9
|
+
/**
|
|
10
|
+
* NostrClient provides the main interface for Nostr protocol operations.
|
|
11
|
+
*/
|
|
12
|
+
export declare class NostrClient {
|
|
13
|
+
private keyManager;
|
|
14
|
+
private relays;
|
|
15
|
+
private subscriptions;
|
|
16
|
+
private eventQueue;
|
|
17
|
+
private pendingOks;
|
|
18
|
+
private subscriptionCounter;
|
|
19
|
+
private closed;
|
|
20
|
+
/**
|
|
21
|
+
* Create a NostrClient instance.
|
|
22
|
+
* @param keyManager Key manager with signing keys
|
|
23
|
+
*/
|
|
24
|
+
constructor(keyManager: NostrKeyManager);
|
|
25
|
+
/**
|
|
26
|
+
* Get the key manager.
|
|
27
|
+
* @returns The key manager instance
|
|
28
|
+
*/
|
|
29
|
+
getKeyManager(): NostrKeyManager;
|
|
30
|
+
/**
|
|
31
|
+
* Connect to one or more relay WebSocket URLs.
|
|
32
|
+
* @param relayUrls Relay URLs to connect to
|
|
33
|
+
* @returns Promise that resolves when all connections are established
|
|
34
|
+
*/
|
|
35
|
+
connect(...relayUrls: string[]): Promise<void>;
|
|
36
|
+
/**
|
|
37
|
+
* Connect to a single relay.
|
|
38
|
+
*/
|
|
39
|
+
private connectToRelay;
|
|
40
|
+
/**
|
|
41
|
+
* Schedule a reconnection attempt for a relay.
|
|
42
|
+
*/
|
|
43
|
+
private scheduleReconnect;
|
|
44
|
+
/**
|
|
45
|
+
* Re-establish all subscriptions for a relay.
|
|
46
|
+
*/
|
|
47
|
+
private resubscribeAll;
|
|
48
|
+
/**
|
|
49
|
+
* Flush queued events to connected relays.
|
|
50
|
+
*/
|
|
51
|
+
private flushEventQueue;
|
|
52
|
+
/**
|
|
53
|
+
* Handle a message from a relay.
|
|
54
|
+
*/
|
|
55
|
+
private handleRelayMessage;
|
|
56
|
+
/**
|
|
57
|
+
* Handle EVENT message from relay.
|
|
58
|
+
*/
|
|
59
|
+
private handleEventMessage;
|
|
60
|
+
/**
|
|
61
|
+
* Handle OK message from relay.
|
|
62
|
+
*/
|
|
63
|
+
private handleOkMessage;
|
|
64
|
+
/**
|
|
65
|
+
* Handle EOSE (End of Stored Events) message from relay.
|
|
66
|
+
*/
|
|
67
|
+
private handleEOSEMessage;
|
|
68
|
+
/**
|
|
69
|
+
* Handle NOTICE message from relay.
|
|
70
|
+
*/
|
|
71
|
+
private handleNoticeMessage;
|
|
72
|
+
/**
|
|
73
|
+
* Handle CLOSED message from relay (subscription closed by relay).
|
|
74
|
+
*/
|
|
75
|
+
private handleClosedMessage;
|
|
76
|
+
/**
|
|
77
|
+
* Disconnect from all relays.
|
|
78
|
+
*/
|
|
79
|
+
disconnect(): void;
|
|
80
|
+
/**
|
|
81
|
+
* Check if connected to at least one relay.
|
|
82
|
+
* @returns true if connected to at least one relay
|
|
83
|
+
*/
|
|
84
|
+
isConnected(): boolean;
|
|
85
|
+
/**
|
|
86
|
+
* Get the set of connected relay URLs.
|
|
87
|
+
* @returns Set of connected relay URLs
|
|
88
|
+
*/
|
|
89
|
+
getConnectedRelays(): Set<string>;
|
|
90
|
+
/**
|
|
91
|
+
* Publish an event to all connected relays.
|
|
92
|
+
* @param event Event to publish
|
|
93
|
+
* @returns Promise that resolves with the event ID
|
|
94
|
+
*/
|
|
95
|
+
publishEvent(event: Event): Promise<string>;
|
|
96
|
+
/**
|
|
97
|
+
* Broadcast an event to all connected relays.
|
|
98
|
+
*/
|
|
99
|
+
private broadcastEvent;
|
|
100
|
+
/**
|
|
101
|
+
* Publish an encrypted direct message (NIP-04).
|
|
102
|
+
* @param recipientPubkeyHex Recipient's public key (hex)
|
|
103
|
+
* @param message Message to send
|
|
104
|
+
* @returns Promise that resolves with the event ID
|
|
105
|
+
*/
|
|
106
|
+
publishEncryptedMessage(recipientPubkeyHex: string, message: string): Promise<string>;
|
|
107
|
+
/**
|
|
108
|
+
* Send a token transfer (encrypted).
|
|
109
|
+
* @param recipientPubkeyHex Recipient's public key (hex)
|
|
110
|
+
* @param tokenJson Token JSON string
|
|
111
|
+
* @returns Promise that resolves with the event ID
|
|
112
|
+
*/
|
|
113
|
+
sendTokenTransfer(recipientPubkeyHex: string, tokenJson: string): Promise<string>;
|
|
114
|
+
/**
|
|
115
|
+
* Publish a nametag binding.
|
|
116
|
+
* @param nametagId Nametag identifier
|
|
117
|
+
* @param unicityAddress Unicity address
|
|
118
|
+
* @returns Promise that resolves with success status
|
|
119
|
+
*/
|
|
120
|
+
publishNametagBinding(nametagId: string, unicityAddress: string): Promise<boolean>;
|
|
121
|
+
/**
|
|
122
|
+
* Subscribe to events matching a filter.
|
|
123
|
+
* @param filter Filter for matching events
|
|
124
|
+
* @param listener Listener for received events
|
|
125
|
+
* @returns Subscription ID
|
|
126
|
+
*/
|
|
127
|
+
subscribe(filter: Filter, listener: NostrEventListener): string;
|
|
128
|
+
/**
|
|
129
|
+
* Subscribe with a specific subscription ID.
|
|
130
|
+
* @param subscriptionId Custom subscription ID
|
|
131
|
+
* @param filter Filter for matching events
|
|
132
|
+
* @param listener Listener for received events
|
|
133
|
+
* @returns Subscription ID
|
|
134
|
+
*/
|
|
135
|
+
subscribe(subscriptionId: string, filter: Filter, listener: NostrEventListener): string;
|
|
136
|
+
/**
|
|
137
|
+
* Unsubscribe from a subscription.
|
|
138
|
+
* @param subscriptionId Subscription ID to unsubscribe
|
|
139
|
+
*/
|
|
140
|
+
unsubscribe(subscriptionId: string): void;
|
|
141
|
+
/**
|
|
142
|
+
* Query for a public key by nametag.
|
|
143
|
+
* @param nametagId Nametag identifier
|
|
144
|
+
* @returns Promise that resolves with the public key hex, or null if not found
|
|
145
|
+
*/
|
|
146
|
+
queryPubkeyByNametag(nametagId: string): Promise<string | null>;
|
|
147
|
+
/**
|
|
148
|
+
* Create and publish a signed event.
|
|
149
|
+
* @param data Unsigned event data
|
|
150
|
+
* @returns Promise that resolves with the event ID
|
|
151
|
+
*/
|
|
152
|
+
createAndPublishEvent(data: UnsignedEventData): Promise<string>;
|
|
153
|
+
}
|
|
154
|
+
//# sourceMappingURL=NostrClient.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"NostrClient.d.ts","sourceRoot":"","sources":["../../../src/client/NostrClient.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AACxD,OAAO,EAAE,KAAK,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AAChE,OAAO,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAE/C,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAuD7D;;GAEG;AACH,qBAAa,WAAW;IACtB,OAAO,CAAC,UAAU,CAAkB;IACpC,OAAO,CAAC,MAAM,CAA2C;IACzD,OAAO,CAAC,aAAa,CAA4C;IACjE,OAAO,CAAC,UAAU,CAAqB;IACvC,OAAO,CAAC,UAAU,CAAqC;IACvD,OAAO,CAAC,mBAAmB,CAAK;IAChC,OAAO,CAAC,MAAM,CAAS;IAEvB;;;OAGG;gBACS,UAAU,EAAE,eAAe;IAIvC;;;OAGG;IACH,aAAa,IAAI,eAAe;IAIhC;;;;OAIG;IACG,OAAO,CAAC,GAAG,SAAS,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IASpD;;OAEG;YACW,cAAc;IAoE5B;;OAEG;IACH,OAAO,CAAC,iBAAiB;IAkBzB;;OAEG;IACH,OAAO,CAAC,cAAc;IAUtB;;OAEG;IACH,OAAO,CAAC,eAAe;IAWvB;;OAEG;IACH,OAAO,CAAC,kBAAkB;IA6B1B;;OAEG;IACH,OAAO,CAAC,kBAAkB;IAiB1B;;OAEG;IACH,OAAO,CAAC,eAAe;IAoBvB;;OAEG;IACH,OAAO,CAAC,iBAAiB;IAWzB;;OAEG;IACH,OAAO,CAAC,mBAAmB;IAM3B;;OAEG;IACH,OAAO,CAAC,mBAAmB;IAY3B;;OAEG;IACH,UAAU,IAAI,IAAI;IA0BlB;;;OAGG;IACH,WAAW,IAAI,OAAO;IAOtB;;;OAGG;IACH,kBAAkB,IAAI,GAAG,CAAC,MAAM,CAAC;IAUjC;;;;OAIG;IACG,YAAY,CAAC,KAAK,EAAE,KAAK,GAAG,OAAO,CAAC,MAAM,CAAC;IAoBjD;;OAEG;YACW,cAAc;IA2B5B;;;;;OAKG;IACG,uBAAuB,CAC3B,kBAAkB,EAAE,MAAM,EAC1B,OAAO,EAAE,MAAM,GACd,OAAO,CAAC,MAAM,CAAC;IAelB;;;;;OAKG;IACG,iBAAiB,CACrB,kBAAkB,EAAE,MAAM,EAC1B,SAAS,EAAE,MAAM,GAChB,OAAO,CAAC,MAAM,CAAC;IAUlB;;;;;OAKG;IACG,qBAAqB,CACzB,SAAS,EAAE,MAAM,EACjB,cAAc,EAAE,MAAM,GACrB,OAAO,CAAC,OAAO,CAAC;IAgBnB;;;;;OAKG;IACH,SAAS,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,kBAAkB,GAAG,MAAM;IAC/D;;;;;;OAMG;IACH,SAAS,CACP,cAAc,EAAE,MAAM,EACtB,MAAM,EAAE,MAAM,EACd,QAAQ,EAAE,kBAAkB,GAC3B,MAAM;IAiCT;;;OAGG;IACH,WAAW,CAAC,cAAc,EAAE,MAAM,GAAG,IAAI;IAczC;;;;OAIG;IACG,oBAAoB,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC;IA8BrE;;;;OAIG;IACG,qBAAqB,CAAC,IAAI,EAAE,iBAAiB,GAAG,OAAO,CAAC,MAAM,CAAC;CAItE"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* NostrEventListener - Callback interface for receiving events and subscription status.
|
|
3
|
+
*/
|
|
4
|
+
import { Event } from '../protocol/Event.js';
|
|
5
|
+
/**
|
|
6
|
+
* Listener interface for Nostr event subscriptions.
|
|
7
|
+
*/
|
|
8
|
+
export interface NostrEventListener {
|
|
9
|
+
/**
|
|
10
|
+
* Called when an event matching the subscription filter is received.
|
|
11
|
+
* @param event The received event
|
|
12
|
+
*/
|
|
13
|
+
onEvent(event: Event): void;
|
|
14
|
+
/**
|
|
15
|
+
* Called when the relay signals End-Of-Stored-Events (EOSE).
|
|
16
|
+
* This indicates that all stored events matching the filter have been sent.
|
|
17
|
+
* @param subscriptionId The subscription ID
|
|
18
|
+
*/
|
|
19
|
+
onEndOfStoredEvents?(subscriptionId: string): void;
|
|
20
|
+
/**
|
|
21
|
+
* Called when a subscription error occurs.
|
|
22
|
+
* @param subscriptionId The subscription ID
|
|
23
|
+
* @param error Error message from the relay
|
|
24
|
+
*/
|
|
25
|
+
onError?(subscriptionId: string, error: string): void;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Simple callback-based event listener.
|
|
29
|
+
* Useful for creating listeners from callback functions.
|
|
30
|
+
*/
|
|
31
|
+
export declare class CallbackEventListener implements NostrEventListener {
|
|
32
|
+
private eventCallback;
|
|
33
|
+
private eoseCallback?;
|
|
34
|
+
private errorCallback?;
|
|
35
|
+
constructor(onEvent: (event: Event) => void, onEndOfStoredEvents?: (subscriptionId: string) => void, onError?: (subscriptionId: string, error: string) => void);
|
|
36
|
+
onEvent(event: Event): void;
|
|
37
|
+
onEndOfStoredEvents(subscriptionId: string): void;
|
|
38
|
+
onError(subscriptionId: string, error: string): void;
|
|
39
|
+
}
|
|
40
|
+
//# sourceMappingURL=NostrEventListener.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"NostrEventListener.d.ts","sourceRoot":"","sources":["../../../src/client/NostrEventListener.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,KAAK,EAAE,MAAM,sBAAsB,CAAC;AAE7C;;GAEG;AACH,MAAM,WAAW,kBAAkB;IACjC;;;OAGG;IACH,OAAO,CAAC,KAAK,EAAE,KAAK,GAAG,IAAI,CAAC;IAE5B;;;;OAIG;IACH,mBAAmB,CAAC,CAAC,cAAc,EAAE,MAAM,GAAG,IAAI,CAAC;IAEnD;;;;OAIG;IACH,OAAO,CAAC,CAAC,cAAc,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;CACvD;AAED;;;GAGG;AACH,qBAAa,qBAAsB,YAAW,kBAAkB;IAC9D,OAAO,CAAC,aAAa,CAAyB;IAC9C,OAAO,CAAC,YAAY,CAAC,CAAmC;IACxD,OAAO,CAAC,aAAa,CAAC,CAAkD;gBAGtE,OAAO,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,EAC/B,mBAAmB,CAAC,EAAE,CAAC,cAAc,EAAE,MAAM,KAAK,IAAI,EACtD,OAAO,CAAC,EAAE,CAAC,cAAc,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,KAAK,IAAI;IAO3D,OAAO,CAAC,KAAK,EAAE,KAAK,GAAG,IAAI;IAI3B,mBAAmB,CAAC,cAAc,EAAE,MAAM,GAAG,IAAI;IAIjD,OAAO,CAAC,cAAc,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI;CAGrD"}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WebSocketAdapter - Cross-platform WebSocket implementation.
|
|
3
|
+
* Provides a unified interface for WebSocket connections in Node.js and browsers.
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* WebSocket message event interface
|
|
7
|
+
*/
|
|
8
|
+
export interface WebSocketMessageEvent {
|
|
9
|
+
data: string | ArrayBuffer | Blob;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* WebSocket close event interface
|
|
13
|
+
*/
|
|
14
|
+
export interface WebSocketCloseEvent {
|
|
15
|
+
code: number;
|
|
16
|
+
reason: string;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* WebSocket error event interface
|
|
20
|
+
*/
|
|
21
|
+
export interface WebSocketErrorEvent {
|
|
22
|
+
message?: string;
|
|
23
|
+
error?: Error;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Unified WebSocket interface for cross-platform compatibility.
|
|
27
|
+
*/
|
|
28
|
+
export interface IWebSocket {
|
|
29
|
+
readonly readyState: number;
|
|
30
|
+
onopen: ((event: unknown) => void) | null;
|
|
31
|
+
onmessage: ((event: WebSocketMessageEvent) => void) | null;
|
|
32
|
+
onclose: ((event: WebSocketCloseEvent) => void) | null;
|
|
33
|
+
onerror: ((event: WebSocketErrorEvent) => void) | null;
|
|
34
|
+
send(data: string): void;
|
|
35
|
+
close(code?: number, reason?: string): void;
|
|
36
|
+
}
|
|
37
|
+
/** WebSocket ready state constants */
|
|
38
|
+
export declare const CONNECTING = 0;
|
|
39
|
+
export declare const OPEN = 1;
|
|
40
|
+
export declare const CLOSING = 2;
|
|
41
|
+
export declare const CLOSED = 3;
|
|
42
|
+
/**
|
|
43
|
+
* Create a WebSocket connection that works in both Node.js and browsers.
|
|
44
|
+
* @param url WebSocket URL (ws:// or wss://)
|
|
45
|
+
* @returns WebSocket instance
|
|
46
|
+
*/
|
|
47
|
+
export declare function createWebSocket(url: string): Promise<IWebSocket>;
|
|
48
|
+
/**
|
|
49
|
+
* Extract string data from WebSocket message event.
|
|
50
|
+
* Handles different message types across platforms.
|
|
51
|
+
* @param event WebSocket message event
|
|
52
|
+
* @returns String message data
|
|
53
|
+
*/
|
|
54
|
+
export declare function extractMessageData(event: WebSocketMessageEvent): string;
|
|
55
|
+
//# sourceMappingURL=WebSocketAdapter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"WebSocketAdapter.d.ts","sourceRoot":"","sources":["../../../src/client/WebSocketAdapter.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;GAEG;AACH,MAAM,WAAW,qBAAqB;IACpC,IAAI,EAAE,MAAM,GAAG,WAAW,GAAG,IAAI,CAAC;CACnC;AAED;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAClC,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;CAChB;AAED;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAClC,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,KAAK,CAAC,EAAE,KAAK,CAAC;CACf;AAED;;GAEG;AACH,MAAM,WAAW,UAAU;IACzB,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,MAAM,EAAE,CAAC,CAAC,KAAK,EAAE,OAAO,KAAK,IAAI,CAAC,GAAG,IAAI,CAAC;IAC1C,SAAS,EAAE,CAAC,CAAC,KAAK,EAAE,qBAAqB,KAAK,IAAI,CAAC,GAAG,IAAI,CAAC;IAC3D,OAAO,EAAE,CAAC,CAAC,KAAK,EAAE,mBAAmB,KAAK,IAAI,CAAC,GAAG,IAAI,CAAC;IACvD,OAAO,EAAE,CAAC,CAAC,KAAK,EAAE,mBAAmB,KAAK,IAAI,CAAC,GAAG,IAAI,CAAC;IACvD,IAAI,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB,KAAK,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CAC7C;AAED,sCAAsC;AACtC,eAAO,MAAM,UAAU,IAAI,CAAC;AAC5B,eAAO,MAAM,IAAI,IAAI,CAAC;AACtB,eAAO,MAAM,OAAO,IAAI,CAAC;AACzB,eAAO,MAAM,MAAM,IAAI,CAAC;AAExB;;;;GAIG;AACH,wBAAsB,eAAe,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,CAAC,CAetE;AAED;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,qBAAqB,GAAG,MAAM,CAgBvE"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Client module - Nostr relay client
|
|
3
|
+
*/
|
|
4
|
+
export { NostrClient } from './NostrClient.js';
|
|
5
|
+
export { CallbackEventListener } from './NostrEventListener.js';
|
|
6
|
+
export type { NostrEventListener } from './NostrEventListener.js';
|
|
7
|
+
export { createWebSocket, extractMessageData, CONNECTING, OPEN, CLOSING, CLOSED, } from './WebSocketAdapter.js';
|
|
8
|
+
export type { IWebSocket } from './WebSocketAdapter.js';
|
|
9
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/client/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EAAE,qBAAqB,EAAE,MAAM,yBAAyB,CAAC;AAChE,YAAY,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAClE,OAAO,EACL,eAAe,EACf,kBAAkB,EAClB,UAAU,EACV,IAAI,EACJ,OAAO,EACP,MAAM,GACP,MAAM,uBAAuB,CAAC;AAC/B,YAAY,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Bech32 encoding/decoding for NIP-19 key formats (npub, nsec).
|
|
3
|
+
* Implements the Bech32 specification for Nostr key encoding.
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Decoded Bech32 data structure
|
|
7
|
+
*/
|
|
8
|
+
export interface DecodedBech32 {
|
|
9
|
+
/** Human-readable part (e.g., "npub", "nsec") */
|
|
10
|
+
hrp: string;
|
|
11
|
+
/** Decoded data bytes */
|
|
12
|
+
data: Uint8Array;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Encode data with Bech32 checksum
|
|
16
|
+
* @param hrp Human-readable part (e.g., "npub", "nsec")
|
|
17
|
+
* @param data Data bytes to encode
|
|
18
|
+
* @returns Bech32-encoded string
|
|
19
|
+
*/
|
|
20
|
+
export declare function encode(hrp: string, data: Uint8Array): string;
|
|
21
|
+
/**
|
|
22
|
+
* Decode a Bech32-encoded string
|
|
23
|
+
* @param bech32String The Bech32 string to decode
|
|
24
|
+
* @returns Decoded data with human-readable part
|
|
25
|
+
*/
|
|
26
|
+
export declare function decode(bech32String: string): DecodedBech32;
|
|
27
|
+
/**
|
|
28
|
+
* Encode a public key as npub
|
|
29
|
+
* @param publicKey 32-byte public key
|
|
30
|
+
* @returns npub-encoded string
|
|
31
|
+
*/
|
|
32
|
+
export declare function encodeNpub(publicKey: Uint8Array): string;
|
|
33
|
+
/**
|
|
34
|
+
* Decode an npub string to public key bytes
|
|
35
|
+
* @param npub npub-encoded string
|
|
36
|
+
* @returns 32-byte public key
|
|
37
|
+
*/
|
|
38
|
+
export declare function decodeNpub(npub: string): Uint8Array;
|
|
39
|
+
/**
|
|
40
|
+
* Encode a private key as nsec
|
|
41
|
+
* @param privateKey 32-byte private key
|
|
42
|
+
* @returns nsec-encoded string
|
|
43
|
+
*/
|
|
44
|
+
export declare function encodeNsec(privateKey: Uint8Array): string;
|
|
45
|
+
/**
|
|
46
|
+
* Decode an nsec string to private key bytes
|
|
47
|
+
* @param nsec nsec-encoded string
|
|
48
|
+
* @returns 32-byte private key
|
|
49
|
+
*/
|
|
50
|
+
export declare function decodeNsec(nsec: string): Uint8Array;
|
|
51
|
+
//# sourceMappingURL=bech32.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bech32.d.ts","sourceRoot":"","sources":["../../../src/crypto/bech32.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAKH;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B,iDAAiD;IACjD,GAAG,EAAE,MAAM,CAAC;IACZ,yBAAyB;IACzB,IAAI,EAAE,UAAU,CAAC;CAClB;AA2FD;;;;;GAKG;AACH,wBAAgB,MAAM,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,UAAU,GAAG,MAAM,CAe5D;AAED;;;;GAIG;AACH,wBAAgB,MAAM,CAAC,YAAY,EAAE,MAAM,GAAG,aAAa,CAsC1D;AAED;;;;GAIG;AACH,wBAAgB,UAAU,CAAC,SAAS,EAAE,UAAU,GAAG,MAAM,CAKxD;AAED;;;;GAIG;AACH,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,UAAU,CASnD;AAED;;;;GAIG;AACH,wBAAgB,UAAU,CAAC,UAAU,EAAE,UAAU,GAAG,MAAM,CAKzD;AAED;;;;GAIG;AACH,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,UAAU,CASnD"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Crypto module - Cryptographic utilities for Nostr protocol
|
|
3
|
+
*/
|
|
4
|
+
export * from './bech32.js';
|
|
5
|
+
export * as Bech32 from './bech32.js';
|
|
6
|
+
export * from './schnorr.js';
|
|
7
|
+
export * as SchnorrSigner from './schnorr.js';
|
|
8
|
+
export * from './nip04.js';
|
|
9
|
+
export * as NIP04 from './nip04.js';
|
|
10
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/crypto/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,cAAc,aAAa,CAAC;AAC5B,OAAO,KAAK,MAAM,MAAM,aAAa,CAAC;AACtC,cAAc,cAAc,CAAC;AAC7B,OAAO,KAAK,aAAa,MAAM,cAAc,CAAC;AAC9C,cAAc,YAAY,CAAC;AAC3B,OAAO,KAAK,KAAK,MAAM,YAAY,CAAC"}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* NIP-04 Encryption implementation.
|
|
3
|
+
* AES-256-CBC encryption with ECDH key agreement and optional GZIP compression.
|
|
4
|
+
* Works in both Node.js and browser environments.
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Derive a shared secret using ECDH (NIP-04 compatible).
|
|
8
|
+
* Returns SHA-256(sharedPoint.x) as the shared secret.
|
|
9
|
+
* @param myPrivateKey 32-byte private key
|
|
10
|
+
* @param theirPublicKey 32-byte x-only public key
|
|
11
|
+
* @returns 32-byte shared secret
|
|
12
|
+
*/
|
|
13
|
+
export declare function deriveSharedSecret(myPrivateKey: Uint8Array, theirPublicKey: Uint8Array): Uint8Array;
|
|
14
|
+
/**
|
|
15
|
+
* Derive a shared secret from hex-encoded keys
|
|
16
|
+
* @param myPrivateKeyHex Hex-encoded private key
|
|
17
|
+
* @param theirPublicKeyHex Hex-encoded public key
|
|
18
|
+
* @returns Hex-encoded shared secret
|
|
19
|
+
*/
|
|
20
|
+
export declare function deriveSharedSecretHex(myPrivateKeyHex: string, theirPublicKeyHex: string): string;
|
|
21
|
+
/**
|
|
22
|
+
* Encrypt a message using NIP-04 encryption.
|
|
23
|
+
* Format: "base64(ciphertext)?iv=base64(iv)"
|
|
24
|
+
* If message > 1KB, automatically compresses with GZIP: "gz:base64(compressed)?iv=base64(iv)"
|
|
25
|
+
* @param message Message to encrypt
|
|
26
|
+
* @param myPrivateKey 32-byte private key
|
|
27
|
+
* @param theirPublicKey 32-byte x-only public key
|
|
28
|
+
* @returns Encrypted content string
|
|
29
|
+
*/
|
|
30
|
+
export declare function encrypt(message: string, myPrivateKey: Uint8Array, theirPublicKey: Uint8Array): Promise<string>;
|
|
31
|
+
/**
|
|
32
|
+
* Encrypt a message using hex-encoded keys
|
|
33
|
+
* @param message Message to encrypt
|
|
34
|
+
* @param myPrivateKeyHex Hex-encoded private key
|
|
35
|
+
* @param theirPublicKeyHex Hex-encoded public key
|
|
36
|
+
* @returns Encrypted content string
|
|
37
|
+
*/
|
|
38
|
+
export declare function encryptHex(message: string, myPrivateKeyHex: string, theirPublicKeyHex: string): Promise<string>;
|
|
39
|
+
/**
|
|
40
|
+
* Decrypt a NIP-04 encrypted message.
|
|
41
|
+
* Automatically decompresses if the message was compressed.
|
|
42
|
+
* @param encryptedContent Encrypted content string
|
|
43
|
+
* @param myPrivateKey 32-byte private key
|
|
44
|
+
* @param theirPublicKey 32-byte x-only public key
|
|
45
|
+
* @returns Decrypted message
|
|
46
|
+
*/
|
|
47
|
+
export declare function decrypt(encryptedContent: string, myPrivateKey: Uint8Array, theirPublicKey: Uint8Array): Promise<string>;
|
|
48
|
+
/**
|
|
49
|
+
* Decrypt a message using hex-encoded keys
|
|
50
|
+
* @param encryptedContent Encrypted content string
|
|
51
|
+
* @param myPrivateKeyHex Hex-encoded private key
|
|
52
|
+
* @param theirPublicKeyHex Hex-encoded public key
|
|
53
|
+
* @returns Decrypted message
|
|
54
|
+
*/
|
|
55
|
+
export declare function decryptHex(encryptedContent: string, myPrivateKeyHex: string, theirPublicKeyHex: string): Promise<string>;
|
|
56
|
+
//# sourceMappingURL=nip04.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"nip04.d.ts","sourceRoot":"","sources":["../../../src/crypto/nip04.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AA4KH;;;;;;GAMG;AACH,wBAAgB,kBAAkB,CAChC,YAAY,EAAE,UAAU,EACxB,cAAc,EAAE,UAAU,GACzB,UAAU,CAsBZ;AAED;;;;;GAKG;AACH,wBAAgB,qBAAqB,CACnC,eAAe,EAAE,MAAM,EACvB,iBAAiB,EAAE,MAAM,GACxB,MAAM,CAIR;AAED;;;;;;;;GAQG;AACH,wBAAsB,OAAO,CAC3B,OAAO,EAAE,MAAM,EACf,YAAY,EAAE,UAAU,EACxB,cAAc,EAAE,UAAU,GACzB,OAAO,CAAC,MAAM,CAAC,CAiCjB;AAED;;;;;;GAMG;AACH,wBAAsB,UAAU,CAC9B,OAAO,EAAE,MAAM,EACf,eAAe,EAAE,MAAM,EACvB,iBAAiB,EAAE,MAAM,GACxB,OAAO,CAAC,MAAM,CAAC,CAIjB;AAED;;;;;;;GAOG;AACH,wBAAsB,OAAO,CAC3B,gBAAgB,EAAE,MAAM,EACxB,YAAY,EAAE,UAAU,EACxB,cAAc,EAAE,UAAU,GACzB,OAAO,CAAC,MAAM,CAAC,CAsCjB;AAED;;;;;;GAMG;AACH,wBAAsB,UAAU,CAC9B,gBAAgB,EAAE,MAAM,EACxB,eAAe,EAAE,MAAM,EACvB,iBAAiB,EAAE,MAAM,GACxB,OAAO,CAAC,MAAM,CAAC,CAIjB"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* BIP-340 Schnorr signature implementation using secp256k1.
|
|
3
|
+
* Uses @noble/curves for cryptographic operations.
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Get the x-only public key from a private key (BIP-340)
|
|
7
|
+
* @param privateKey 32-byte private key
|
|
8
|
+
* @returns 32-byte x-only public key
|
|
9
|
+
*/
|
|
10
|
+
export declare function getPublicKey(privateKey: Uint8Array): Uint8Array;
|
|
11
|
+
/**
|
|
12
|
+
* Get the x-only public key from a hex-encoded private key
|
|
13
|
+
* @param privateKeyHex Hex-encoded private key
|
|
14
|
+
* @returns Hex-encoded x-only public key
|
|
15
|
+
*/
|
|
16
|
+
export declare function getPublicKeyHex(privateKeyHex: string): string;
|
|
17
|
+
/**
|
|
18
|
+
* Sign a message using BIP-340 Schnorr signature
|
|
19
|
+
* @param message 32-byte message hash to sign
|
|
20
|
+
* @param privateKey 32-byte private key
|
|
21
|
+
* @returns 64-byte Schnorr signature (R.x || s)
|
|
22
|
+
*/
|
|
23
|
+
export declare function sign(message: Uint8Array, privateKey: Uint8Array): Uint8Array;
|
|
24
|
+
/**
|
|
25
|
+
* Sign a message and return hex-encoded signature
|
|
26
|
+
* @param message 32-byte message hash to sign
|
|
27
|
+
* @param privateKey 32-byte private key
|
|
28
|
+
* @returns Hex-encoded 64-byte Schnorr signature
|
|
29
|
+
*/
|
|
30
|
+
export declare function signHex(message: Uint8Array, privateKey: Uint8Array): string;
|
|
31
|
+
/**
|
|
32
|
+
* Verify a BIP-340 Schnorr signature
|
|
33
|
+
* @param signature 64-byte Schnorr signature
|
|
34
|
+
* @param message 32-byte message hash
|
|
35
|
+
* @param publicKey 32-byte x-only public key
|
|
36
|
+
* @returns true if the signature is valid
|
|
37
|
+
*/
|
|
38
|
+
export declare function verify(signature: Uint8Array, message: Uint8Array, publicKey: Uint8Array): boolean;
|
|
39
|
+
/**
|
|
40
|
+
* Verify a hex-encoded Schnorr signature
|
|
41
|
+
* @param signatureHex Hex-encoded 64-byte signature
|
|
42
|
+
* @param message 32-byte message hash
|
|
43
|
+
* @param publicKeyHex Hex-encoded 32-byte public key
|
|
44
|
+
* @returns true if the signature is valid
|
|
45
|
+
*/
|
|
46
|
+
export declare function verifyHex(signatureHex: string, message: Uint8Array, publicKeyHex: string): boolean;
|
|
47
|
+
//# sourceMappingURL=schnorr.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schnorr.d.ts","sourceRoot":"","sources":["../../../src/crypto/schnorr.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAKH;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,UAAU,EAAE,UAAU,GAAG,UAAU,CAK/D;AAED;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,aAAa,EAAE,MAAM,GAAG,MAAM,CAI7D;AAED;;;;;GAKG;AACH,wBAAgB,IAAI,CAAC,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,GAAG,UAAU,CAQ5E;AAED;;;;;GAKG;AACH,wBAAgB,OAAO,CAAC,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,GAAG,MAAM,CAE3E;AAED;;;;;;GAMG;AACH,wBAAgB,MAAM,CACpB,SAAS,EAAE,UAAU,EACrB,OAAO,EAAE,UAAU,EACnB,SAAS,EAAE,UAAU,GACpB,OAAO,CAgBT;AAED;;;;;;GAMG;AACH,wBAAgB,SAAS,CACvB,YAAY,EAAE,MAAM,EACpB,OAAO,EAAE,UAAU,EACnB,YAAY,EAAE,MAAM,GACnB,OAAO,CAQT"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Unicity Nostr SDK
|
|
3
|
+
*
|
|
4
|
+
* A TypeScript SDK for Nostr protocol with Unicity extensions.
|
|
5
|
+
* Works in both Node.js and browser environments.
|
|
6
|
+
*
|
|
7
|
+
* Features:
|
|
8
|
+
* - BIP-340 Schnorr signatures
|
|
9
|
+
* - NIP-04 encrypted direct messages with GZIP compression
|
|
10
|
+
* - Multi-relay WebSocket connections with auto-reconnection
|
|
11
|
+
* - Token transfers over Nostr
|
|
12
|
+
* - Privacy-preserving nametag bindings
|
|
13
|
+
*
|
|
14
|
+
* @packageDocumentation
|
|
15
|
+
*/
|
|
16
|
+
export { NostrKeyManager } from './NostrKeyManager.js';
|
|
17
|
+
export * from './crypto/index.js';
|
|
18
|
+
export { Bech32, SchnorrSigner, NIP04, } from './crypto/index.js';
|
|
19
|
+
export * from './protocol/index.js';
|
|
20
|
+
export { EventKinds } from './protocol/index.js';
|
|
21
|
+
export * from './client/index.js';
|
|
22
|
+
export * from './nametag/index.js';
|
|
23
|
+
export { NametagUtils, NametagBinding } from './nametag/index.js';
|
|
24
|
+
export * from './token/index.js';
|
|
25
|
+
export { TokenTransferProtocol } from './token/index.js';
|
|
26
|
+
export type { DecodedBech32, } from './crypto/bech32.js';
|
|
27
|
+
export type { EventTag, UnsignedEventData, SignedEventData, } from './protocol/Event.js';
|
|
28
|
+
export type { FilterData, } from './protocol/Filter.js';
|
|
29
|
+
export type { NostrEventListener, } from './client/NostrEventListener.js';
|
|
30
|
+
export type { IWebSocket, WebSocketMessageEvent, WebSocketCloseEvent, WebSocketErrorEvent, } from './client/WebSocketAdapter.js';
|
|
31
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAGH,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAGvD,cAAc,mBAAmB,CAAC;AAClC,OAAO,EACL,MAAM,EACN,aAAa,EACb,KAAK,GACN,MAAM,mBAAmB,CAAC;AAG3B,cAAc,qBAAqB,CAAC;AACpC,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAGjD,cAAc,mBAAmB,CAAC;AAGlC,cAAc,oBAAoB,CAAC;AACnC,OAAO,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAGlE,cAAc,kBAAkB,CAAC;AACjC,OAAO,EAAE,qBAAqB,EAAE,MAAM,kBAAkB,CAAC;AAGzD,YAAY,EACV,aAAa,GACd,MAAM,oBAAoB,CAAC;AAE5B,YAAY,EACV,QAAQ,EACR,iBAAiB,EACjB,eAAe,GAChB,MAAM,qBAAqB,CAAC;AAE7B,YAAY,EACV,UAAU,GACX,MAAM,sBAAsB,CAAC;AAE9B,YAAY,EACV,kBAAkB,GACnB,MAAM,gCAAgC,CAAC;AAExC,YAAY,EACV,UAAU,EACV,qBAAqB,EACrB,mBAAmB,EACnB,mBAAmB,GACpB,MAAM,8BAA8B,CAAC"}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* NametagBinding - Create and parse nametag binding events.
|
|
3
|
+
* Uses kind 30078 (APP_DATA) for parameterized replaceable events.
|
|
4
|
+
*/
|
|
5
|
+
import { NostrKeyManager } from '../NostrKeyManager.js';
|
|
6
|
+
import { Event } from '../protocol/Event.js';
|
|
7
|
+
import { Filter } from '../protocol/Filter.js';
|
|
8
|
+
/**
|
|
9
|
+
* Create a nametag binding event.
|
|
10
|
+
*
|
|
11
|
+
* Event structure:
|
|
12
|
+
* - Kind: 30078 (APP_DATA - parameterized replaceable)
|
|
13
|
+
* - Tags:
|
|
14
|
+
* - ["d", "<hashed_nametag>"] - Required for parameterized replaceable
|
|
15
|
+
* - ["nametag", "<hashed_nametag>"] - Hashed for privacy
|
|
16
|
+
* - ["t", "<hashed_nametag>"] - Indexed tag for relay search
|
|
17
|
+
* - ["address", "<unicity_addr>"] - Unicity blockchain address
|
|
18
|
+
* - Content: JSON with nametag_hash, address, verified timestamp
|
|
19
|
+
*
|
|
20
|
+
* @param keyManager Key manager with signing keys
|
|
21
|
+
* @param nametagId Nametag identifier (phone number or username)
|
|
22
|
+
* @param unicityAddress Unicity blockchain address
|
|
23
|
+
* @param defaultCountry Default country code for phone normalization
|
|
24
|
+
* @returns Signed event
|
|
25
|
+
*/
|
|
26
|
+
export declare function createBindingEvent(keyManager: NostrKeyManager, nametagId: string, unicityAddress: string, defaultCountry?: string): Promise<Event>;
|
|
27
|
+
/**
|
|
28
|
+
* Create a filter to query pubkey by nametag.
|
|
29
|
+
* Query direction: nametag → pubkey
|
|
30
|
+
*
|
|
31
|
+
* @param nametagId Nametag identifier
|
|
32
|
+
* @param defaultCountry Default country code for phone normalization
|
|
33
|
+
* @returns Filter for nametag binding events
|
|
34
|
+
*/
|
|
35
|
+
export declare function createNametagToPubkeyFilter(nametagId: string, defaultCountry?: string): Filter;
|
|
36
|
+
/**
|
|
37
|
+
* Create a filter to query nametags by pubkey.
|
|
38
|
+
* Query direction: pubkey → nametags
|
|
39
|
+
*
|
|
40
|
+
* @param nostrPubkey Nostr public key (hex)
|
|
41
|
+
* @returns Filter for nametag binding events
|
|
42
|
+
*/
|
|
43
|
+
export declare function createPubkeyToNametagFilter(nostrPubkey: string): Filter;
|
|
44
|
+
/**
|
|
45
|
+
* Parse the hashed nametag from a binding event.
|
|
46
|
+
* Tries tags first, then content JSON.
|
|
47
|
+
*
|
|
48
|
+
* @param event Binding event
|
|
49
|
+
* @returns Hashed nametag, or undefined if not found
|
|
50
|
+
*/
|
|
51
|
+
export declare function parseNametagHashFromEvent(event: Event): string | undefined;
|
|
52
|
+
/**
|
|
53
|
+
* Parse the Unicity address from a binding event.
|
|
54
|
+
* Tries tags first, then content JSON.
|
|
55
|
+
*
|
|
56
|
+
* @param event Binding event
|
|
57
|
+
* @returns Unicity address, or undefined if not found
|
|
58
|
+
*/
|
|
59
|
+
export declare function parseAddressFromEvent(event: Event): string | undefined;
|
|
60
|
+
/**
|
|
61
|
+
* Verify that a binding event is valid.
|
|
62
|
+
* Checks signature and structure.
|
|
63
|
+
*
|
|
64
|
+
* @param event Event to verify
|
|
65
|
+
* @returns true if the binding event is valid
|
|
66
|
+
*/
|
|
67
|
+
export declare function isValidBindingEvent(event: Event): boolean;
|
|
68
|
+
//# sourceMappingURL=NametagBinding.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"NametagBinding.d.ts","sourceRoot":"","sources":["../../../src/nametag/NametagBinding.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AACxD,OAAO,EAAE,KAAK,EAAE,MAAM,sBAAsB,CAAC;AAC7C,OAAO,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAgB/C;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAsB,kBAAkB,CACtC,UAAU,EAAE,eAAe,EAC3B,SAAS,EAAE,MAAM,EACjB,cAAc,EAAE,MAAM,EACtB,cAAc,GAAE,MAAwB,GACvC,OAAO,CAAC,KAAK,CAAC,CAqBhB;AAED;;;;;;;GAOG;AACH,wBAAgB,2BAA2B,CACzC,SAAS,EAAE,MAAM,EACjB,cAAc,GAAE,MAAwB,GACvC,MAAM,CAOR;AAED;;;;;;GAMG;AACH,wBAAgB,2BAA2B,CAAC,WAAW,EAAE,MAAM,GAAG,MAAM,CAMvE;AAED;;;;;;GAMG;AACH,wBAAgB,yBAAyB,CAAC,KAAK,EAAE,KAAK,GAAG,MAAM,GAAG,SAAS,CAoB1E;AAED;;;;;;GAMG;AACH,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,KAAK,GAAG,MAAM,GAAG,SAAS,CActE;AAED;;;;;;GAMG;AACH,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,KAAK,GAAG,OAAO,CAuBzD"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* NametagUtils - Privacy-preserving nametag normalization and hashing.
|
|
3
|
+
* Supports phone number normalization to E.164 format.
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Normalize a nametag for hashing.
|
|
7
|
+
* - If it looks like a phone number, normalize to E.164
|
|
8
|
+
* - Otherwise, lowercase and remove @unicity suffix
|
|
9
|
+
* @param nametag Nametag to normalize
|
|
10
|
+
* @param defaultCountry Default country code for phone normalization
|
|
11
|
+
* @returns Normalized nametag
|
|
12
|
+
*/
|
|
13
|
+
export declare function normalizeNametag(nametag: string, defaultCountry?: string): string;
|
|
14
|
+
/**
|
|
15
|
+
* Hash a nametag with the standard salt.
|
|
16
|
+
* @param nametag Nametag to hash
|
|
17
|
+
* @param defaultCountry Default country code for phone normalization
|
|
18
|
+
* @returns Hex-encoded SHA-256 hash
|
|
19
|
+
*/
|
|
20
|
+
export declare function hashNametag(nametag: string, defaultCountry?: string): string;
|
|
21
|
+
/**
|
|
22
|
+
* Compare two nametags for equality (handling format variations).
|
|
23
|
+
* @param tag1 First nametag
|
|
24
|
+
* @param tag2 Second nametag
|
|
25
|
+
* @param defaultCountry Default country code for phone normalization
|
|
26
|
+
* @returns true if the nametags represent the same identity
|
|
27
|
+
*/
|
|
28
|
+
export declare function areSameNametag(tag1: string, tag2: string, defaultCountry?: string): boolean;
|
|
29
|
+
/**
|
|
30
|
+
* Format a nametag for display (privacy-preserving).
|
|
31
|
+
* For phone numbers, hides middle digits.
|
|
32
|
+
* @param nametag Nametag to format
|
|
33
|
+
* @param defaultCountry Default country code for phone normalization
|
|
34
|
+
* @returns Display-safe formatted nametag
|
|
35
|
+
*/
|
|
36
|
+
export declare function formatForDisplay(nametag: string, defaultCountry?: string): string;
|
|
37
|
+
/**
|
|
38
|
+
* Check if a string is a valid phone number.
|
|
39
|
+
* @param str String to check
|
|
40
|
+
* @param defaultCountry Default country code
|
|
41
|
+
* @returns true if the string is a valid phone number
|
|
42
|
+
*/
|
|
43
|
+
export declare function isPhoneNumber(str: string, defaultCountry?: string): boolean;
|
|
44
|
+
//# sourceMappingURL=NametagUtils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"NametagUtils.d.ts","sourceRoot":"","sources":["../../../src/nametag/NametagUtils.ts"],"names":[],"mappings":"AAAA;;;GAGG;AA4EH;;;;;;;GAOG;AACH,wBAAgB,gBAAgB,CAC9B,OAAO,EAAE,MAAM,EACf,cAAc,GAAE,MAAwB,GACvC,MAAM,CAkBR;AAED;;;;;GAKG;AACH,wBAAgB,WAAW,CACzB,OAAO,EAAE,MAAM,EACf,cAAc,GAAE,MAAwB,GACvC,MAAM,CAGR;AAED;;;;;;GAMG;AACH,wBAAgB,cAAc,CAC5B,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,MAAM,EACZ,cAAc,GAAE,MAAwB,GACvC,OAAO,CAIT;AAED;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAC9B,OAAO,EAAE,MAAM,EACf,cAAc,GAAE,MAAwB,GACvC,MAAM,CAiBR;AAED;;;;;GAKG;AACH,wBAAgB,aAAa,CAC3B,GAAG,EAAE,MAAM,EACX,cAAc,GAAE,MAAwB,GACvC,OAAO,CAOT"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Nametag module - Privacy-preserving identity bindings
|
|
3
|
+
*/
|
|
4
|
+
export * as NametagUtils from './NametagUtils.js';
|
|
5
|
+
export * from './NametagUtils.js';
|
|
6
|
+
export * as NametagBinding from './NametagBinding.js';
|
|
7
|
+
export * from './NametagBinding.js';
|
|
8
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/nametag/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,YAAY,MAAM,mBAAmB,CAAC;AAClD,cAAc,mBAAmB,CAAC;AAClC,OAAO,KAAK,cAAc,MAAM,qBAAqB,CAAC;AACtD,cAAc,qBAAqB,CAAC"}
|