@hashtree/nostr 0.1.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/LICENSE +21 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +14 -0
- package/dist/index.js.map +1 -0
- package/dist/resolver/index.d.ts +5 -0
- package/dist/resolver/index.d.ts.map +1 -0
- package/dist/resolver/index.js +5 -0
- package/dist/resolver/index.js.map +1 -0
- package/dist/resolver/nostr.d.ts +82 -0
- package/dist/resolver/nostr.d.ts.map +1 -0
- package/dist/resolver/nostr.js +868 -0
- package/dist/resolver/nostr.js.map +1 -0
- package/dist/webrtc/index.d.ts +5 -0
- package/dist/webrtc/index.d.ts.map +1 -0
- package/dist/webrtc/index.js +6 -0
- package/dist/webrtc/index.js.map +1 -0
- package/dist/webrtc/lruCache.d.ts +20 -0
- package/dist/webrtc/lruCache.d.ts.map +1 -0
- package/dist/webrtc/lruCache.js +59 -0
- package/dist/webrtc/lruCache.js.map +1 -0
- package/dist/webrtc/peer.d.ts +122 -0
- package/dist/webrtc/peer.d.ts.map +1 -0
- package/dist/webrtc/peer.js +583 -0
- package/dist/webrtc/peer.js.map +1 -0
- package/dist/webrtc/protocol.d.ts +76 -0
- package/dist/webrtc/protocol.d.ts.map +1 -0
- package/dist/webrtc/protocol.js +167 -0
- package/dist/webrtc/protocol.js.map +1 -0
- package/dist/webrtc/store.d.ts +190 -0
- package/dist/webrtc/store.d.ts.map +1 -0
- package/dist/webrtc/store.js +1043 -0
- package/dist/webrtc/store.js.map +1 -0
- package/dist/webrtc/types.d.ts +197 -0
- package/dist/webrtc/types.d.ts.map +1 -0
- package/dist/webrtc/types.js +46 -0
- package/dist/webrtc/types.js.map +1 -0
- package/package.json +43 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Sirius Business Ltd.
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @hashtree/nostr - Nostr integration for hashtree
|
|
3
|
+
*
|
|
4
|
+
* Provides WebRTC P2P storage and Nostr ref resolver
|
|
5
|
+
*/
|
|
6
|
+
export { WebRTCStore, DEFAULT_RELAYS, Peer, PeerId, generateUuid, MAX_HTL, MSG_TYPE_REQUEST, MSG_TYPE_RESPONSE, FRAGMENT_SIZE, encodeRequest, encodeResponse, parseMessage, createRequest, createResponse, createFragmentResponse, hashToKey, verifyHash, generatePeerHTLConfig, decrementHTL, shouldForward, type SignalingMessage, type WebRTCStoreConfig, type PeerStatus, type WebRTCStoreEvent, type WebRTCStoreEventHandler, type EventSigner, type EventEncrypter, type EventDecrypter, type GiftWrapper, type GiftUnwrapper, type SignedEvent, type PeerPool, type PeerClassifier, type PoolConfig, type WebRTCStats, type BandwidthSample, type DataRequest, type DataResponse, type PeerHTLConfig, type PendingRequest, } from './webrtc/index.js';
|
|
7
|
+
export { createNostrRefResolver, createNostrRefResolver as createNostrRootResolver, type NostrRefResolverConfig, type NostrRefResolverConfig as NostrRootResolverConfig, type NostrEvent, type NostrFilter, type Nip19Like, type VisibilityCallbacks, type ParsedTreeVisibility, } from './resolver/index.js';
|
|
8
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,EACL,WAAW,EACX,cAAc,EACd,IAAI,EACJ,MAAM,EACN,YAAY,EACZ,OAAO,EACP,gBAAgB,EAChB,iBAAiB,EACjB,aAAa,EAEb,aAAa,EACb,cAAc,EACd,YAAY,EACZ,aAAa,EACb,cAAc,EACd,sBAAsB,EACtB,SAAS,EACT,UAAU,EACV,qBAAqB,EACrB,YAAY,EACZ,aAAa,EACb,KAAK,gBAAgB,EACrB,KAAK,iBAAiB,EACtB,KAAK,UAAU,EACf,KAAK,gBAAgB,EACrB,KAAK,uBAAuB,EAC5B,KAAK,WAAW,EAChB,KAAK,cAAc,EACnB,KAAK,cAAc,EACnB,KAAK,WAAW,EAChB,KAAK,aAAa,EAClB,KAAK,WAAW,EAChB,KAAK,QAAQ,EACb,KAAK,cAAc,EACnB,KAAK,UAAU,EACf,KAAK,WAAW,EAChB,KAAK,eAAe,EACpB,KAAK,WAAW,EAChB,KAAK,YAAY,EACjB,KAAK,aAAa,EAClB,KAAK,cAAc,GACpB,MAAM,mBAAmB,CAAC;AAG3B,OAAO,EACL,sBAAsB,EAEtB,sBAAsB,IAAI,uBAAuB,EACjD,KAAK,sBAAsB,EAE3B,KAAK,sBAAsB,IAAI,uBAAuB,EACtD,KAAK,UAAU,EACf,KAAK,WAAW,EAChB,KAAK,SAAS,EACd,KAAK,mBAAmB,EACxB,KAAK,oBAAoB,GAC1B,MAAM,qBAAqB,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @hashtree/nostr - Nostr integration for hashtree
|
|
3
|
+
*
|
|
4
|
+
* Provides WebRTC P2P storage and Nostr ref resolver
|
|
5
|
+
*/
|
|
6
|
+
// WebRTC P2P store
|
|
7
|
+
export { WebRTCStore, DEFAULT_RELAYS, Peer, PeerId, generateUuid, MAX_HTL, MSG_TYPE_REQUEST, MSG_TYPE_RESPONSE, FRAGMENT_SIZE,
|
|
8
|
+
// Protocol functions
|
|
9
|
+
encodeRequest, encodeResponse, parseMessage, createRequest, createResponse, createFragmentResponse, hashToKey, verifyHash, generatePeerHTLConfig, decrementHTL, shouldForward, } from './webrtc/index.js';
|
|
10
|
+
// Ref resolvers
|
|
11
|
+
export { createNostrRefResolver,
|
|
12
|
+
// Legacy alias
|
|
13
|
+
createNostrRefResolver as createNostrRootResolver, } from './resolver/index.js';
|
|
14
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,mBAAmB;AACnB,OAAO,EACL,WAAW,EACX,cAAc,EACd,IAAI,EACJ,MAAM,EACN,YAAY,EACZ,OAAO,EACP,gBAAgB,EAChB,iBAAiB,EACjB,aAAa;AACb,qBAAqB;AACrB,aAAa,EACb,cAAc,EACd,YAAY,EACZ,aAAa,EACb,cAAc,EACd,sBAAsB,EACtB,SAAS,EACT,UAAU,EACV,qBAAqB,EACrB,YAAY,EACZ,aAAa,GAqBd,MAAM,mBAAmB,CAAC;AAE3B,gBAAgB;AAChB,OAAO,EACL,sBAAsB;AACtB,eAAe;AACf,sBAAsB,IAAI,uBAAuB,GASlD,MAAM,qBAAqB,CAAC"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Ref resolvers - map human-readable keys to merkle root hashes (refs)
|
|
3
|
+
*/
|
|
4
|
+
export { createNostrRefResolver, type NostrRefResolverConfig, type VisibilityCallbacks, type ParsedTreeVisibility, type NostrRefResolverConfig as NostrRootResolverConfig, type NostrEvent, type NostrFilter, type Nip19Like, } from './nostr.js';
|
|
5
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/resolver/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,EACL,sBAAsB,EACtB,KAAK,sBAAsB,EAC3B,KAAK,mBAAmB,EACxB,KAAK,oBAAoB,EAEzB,KAAK,sBAAsB,IAAI,uBAAuB,EACtD,KAAK,UAAU,EACf,KAAK,WAAW,EAChB,KAAK,SAAS,GACf,MAAM,YAAY,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/resolver/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,EACL,sBAAsB,GASvB,MAAM,YAAY,CAAC"}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* NostrRefResolver - Maps npub/treename keys to merkle root hashes (refs)
|
|
3
|
+
*
|
|
4
|
+
* Key format: "npub1.../treename"
|
|
5
|
+
*
|
|
6
|
+
* This resolver provides direct callback subscriptions that bypass React's
|
|
7
|
+
* render cycle. Components can subscribe to hash changes and update directly
|
|
8
|
+
* (e.g., MediaSource append) without triggering re-renders.
|
|
9
|
+
*/
|
|
10
|
+
import type { RefResolver } from '@hashtree/core';
|
|
11
|
+
import { type TreeVisibility } from '@hashtree/core';
|
|
12
|
+
export interface NostrEvent {
|
|
13
|
+
id?: string;
|
|
14
|
+
pubkey: string;
|
|
15
|
+
kind: number;
|
|
16
|
+
content: string;
|
|
17
|
+
tags: string[][];
|
|
18
|
+
created_at: number;
|
|
19
|
+
}
|
|
20
|
+
export interface Nip19Like {
|
|
21
|
+
decode(str: string): {
|
|
22
|
+
type: string;
|
|
23
|
+
data: unknown;
|
|
24
|
+
};
|
|
25
|
+
npubEncode(pubkey: string): string;
|
|
26
|
+
}
|
|
27
|
+
export interface NostrFilter {
|
|
28
|
+
kinds?: number[];
|
|
29
|
+
authors?: string[];
|
|
30
|
+
'#d'?: string[];
|
|
31
|
+
'#l'?: string[];
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Parsed visibility info from a nostr event
|
|
35
|
+
*/
|
|
36
|
+
export interface ParsedTreeVisibility {
|
|
37
|
+
hash: string;
|
|
38
|
+
visibility: TreeVisibility;
|
|
39
|
+
/** Plaintext key (for public trees) */
|
|
40
|
+
key?: string;
|
|
41
|
+
/** Encrypted key (for link-visible trees) - decrypt with link key */
|
|
42
|
+
encryptedKey?: string;
|
|
43
|
+
/** Key ID (for link-visible trees) - identifies which link key to use */
|
|
44
|
+
keyId?: string;
|
|
45
|
+
/** Self-encrypted key (for private/link-visible trees) - decrypt with NIP-44 */
|
|
46
|
+
selfEncryptedKey?: string;
|
|
47
|
+
/** Self-encrypted link key (for link-visible trees) - allows owner to recover link key for sharing */
|
|
48
|
+
selfEncryptedLinkKey?: string;
|
|
49
|
+
}
|
|
50
|
+
/** Event type for publishing (created_at optional - usually auto-set by NDK) */
|
|
51
|
+
export type NostrPublishEvent = Omit<NostrEvent, 'id' | 'pubkey' | 'created_at'> & {
|
|
52
|
+
created_at?: number;
|
|
53
|
+
};
|
|
54
|
+
/**
|
|
55
|
+
* Visibility callbacks for encryption/decryption
|
|
56
|
+
* Used for private trees (NIP-44 self-encryption)
|
|
57
|
+
*/
|
|
58
|
+
export interface VisibilityCallbacks {
|
|
59
|
+
/** NIP-44 encrypt data to a pubkey */
|
|
60
|
+
encrypt?: (data: Uint8Array, toPubkey: string) => Promise<string>;
|
|
61
|
+
/** NIP-44 decrypt data from a pubkey */
|
|
62
|
+
decrypt?: (ciphertext: string, fromPubkey: string) => Promise<Uint8Array | null>;
|
|
63
|
+
/** Get link key from URL context (for link-visible trees) */
|
|
64
|
+
getLinkKey?: () => Uint8Array | null;
|
|
65
|
+
}
|
|
66
|
+
export interface NostrRefResolverConfig {
|
|
67
|
+
/** Subscribe to nostr events - returns unsubscribe function */
|
|
68
|
+
subscribe: (filter: NostrFilter, onEvent: (event: NostrEvent) => void) => () => void;
|
|
69
|
+
/** Publish a nostr event - returns true on success. created_at is optional (for delete events) */
|
|
70
|
+
publish: (event: NostrPublishEvent) => Promise<boolean>;
|
|
71
|
+
/** Get current user's pubkey (for ownership checks) */
|
|
72
|
+
getPubkey: () => string | null;
|
|
73
|
+
/** nip19 encode/decode functions from nostr-tools */
|
|
74
|
+
nip19: Nip19Like;
|
|
75
|
+
/** Optional visibility callbacks for private/link-visible trees */
|
|
76
|
+
visibility?: VisibilityCallbacks;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Create a NostrRefResolver instance
|
|
80
|
+
*/
|
|
81
|
+
export declare function createNostrRefResolver(config: NostrRefResolverConfig): RefResolver;
|
|
82
|
+
//# sourceMappingURL=nostr.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"nostr.d.ts","sourceRoot":"","sources":["../../src/resolver/nostr.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,KAAK,EAAE,WAAW,EAAqF,MAAM,gBAAgB,CAAC;AAErI,OAAO,EAIL,KAAK,cAAc,EACpB,MAAM,gBAAgB,CAAC;AAGxB,MAAM,WAAW,UAAU;IACzB,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,MAAM,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