@candypoets/nipworker 0.96.3 → 0.96.5
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 +206 -73
- package/crates/native-ffi/README.md +14 -151
- package/crates/native-ffi/ios/README.md +4 -50
- package/crates/native-ffi/react-native/README.md +8 -7
- package/crates/native-ffi/react-native/android/build.gradle +1 -0
- package/crates/native-ffi/react-native/android/src/main/cpp/NipworkerByteRuntime.cpp +348 -0
- package/crates/native-ffi/react-native/android/src/main/java/com/candypoets/nipworker/reactnative/NipworkerHooks.kt +292 -0
- package/crates/native-ffi/react-native/android/src/main/java/com/candypoets/nipworker/reactnative/NipworkerReactNativeModule.kt +283 -89
- package/crates/native-ffi/react-native/android/src/main/java/nostr/fb/AddressPointer.java +75 -0
- package/crates/native-ffi/react-native/android/src/main/java/nostr/fb/ArticleBlock.java +102 -0
- package/crates/native-ffi/react-native/android/src/main/java/nostr/fb/ArticleBlockType.java +23 -0
- package/crates/native-ffi/react-native/android/src/main/java/nostr/fb/ArticleEntity.java +80 -0
- package/crates/native-ffi/react-native/android/src/main/java/nostr/fb/ArticleInline.java +85 -0
- package/crates/native-ffi/react-native/android/src/main/java/nostr/fb/ArticleInlineType.java +24 -0
- package/crates/native-ffi/react-native/android/src/main/java/nostr/fb/BadgeAwardRecipient.java +61 -0
- package/crates/native-ffi/react-native/android/src/main/java/nostr/fb/BufferFull.java +52 -0
- package/crates/native-ffi/react-native/android/src/main/java/nostr/fb/CacheInput.java +16 -0
- package/crates/native-ffi/react-native/android/src/main/java/nostr/fb/CacheInputMessage.java +57 -0
- package/crates/native-ffi/react-native/android/src/main/java/nostr/fb/CacheRequest.java +84 -0
- package/crates/native-ffi/react-native/android/src/main/java/nostr/fb/CacheResponse.java +67 -0
- package/crates/native-ffi/react-native/android/src/main/java/nostr/fb/CashuData.java +55 -0
- package/crates/native-ffi/react-native/android/src/main/java/nostr/fb/ChatLimiterPipeConfig.java +74 -0
- package/crates/native-ffi/react-native/android/src/main/java/nostr/fb/CodeData.java +61 -0
- package/crates/native-ffi/react-native/android/src/main/java/nostr/fb/ConnectionStatus.java +68 -0
- package/crates/native-ffi/react-native/android/src/main/java/nostr/fb/Contact.java +70 -0
- package/crates/native-ffi/react-native/android/src/main/java/nostr/fb/ContentBlock.java +70 -0
- package/crates/native-ffi/react-native/android/src/main/java/nostr/fb/ContentData.java +23 -0
- package/crates/native-ffi/react-native/android/src/main/java/nostr/fb/Coordinate.java +75 -0
- package/crates/native-ffi/react-native/android/src/main/java/nostr/fb/CountResponse.java +60 -0
- package/crates/native-ffi/react-native/android/src/main/java/nostr/fb/CounterPipeConfig.java +67 -0
- package/crates/native-ffi/react-native/android/src/main/java/nostr/fb/DLEQProof.java +69 -0
- package/crates/native-ffi/react-native/android/src/main/java/nostr/fb/Emoji.java +62 -0
- package/crates/native-ffi/react-native/android/src/main/java/nostr/fb/EmojiData.java +68 -0
- package/crates/native-ffi/react-native/android/src/main/java/nostr/fb/Eoce.java +55 -0
- package/crates/native-ffi/react-native/android/src/main/java/nostr/fb/EventPointer.java +74 -0
- package/crates/native-ffi/react-native/android/src/main/java/nostr/fb/GetPublicKey.java +43 -0
- package/crates/native-ffi/react-native/android/src/main/java/nostr/fb/HTLCWitness.java +64 -0
- package/crates/native-ffi/react-native/android/src/main/java/nostr/fb/HashtagData.java +55 -0
- package/crates/native-ffi/react-native/android/src/main/java/nostr/fb/HistoryTag.java +74 -0
- package/crates/native-ffi/react-native/android/src/main/java/nostr/fb/ImageData.java +67 -0
- package/crates/native-ffi/react-native/android/src/main/java/nostr/fb/ImetaTag.java +100 -0
- package/crates/native-ffi/react-native/android/src/main/java/nostr/fb/Kind0Parsed.java +168 -0
- package/crates/native-ffi/react-native/android/src/main/java/nostr/fb/Kind10002Parsed.java +59 -0
- package/crates/native-ffi/react-native/android/src/main/java/nostr/fb/Kind10019Parsed.java +73 -0
- package/crates/native-ffi/react-native/android/src/main/java/nostr/fb/Kind1018Parsed.java +79 -0
- package/crates/native-ffi/react-native/android/src/main/java/nostr/fb/Kind1068Parsed.java +107 -0
- package/crates/native-ffi/react-native/android/src/main/java/nostr/fb/Kind1111Parsed.java +159 -0
- package/crates/native-ffi/react-native/android/src/main/java/nostr/fb/Kind1311Parsed.java +91 -0
- package/crates/native-ffi/react-native/android/src/main/java/nostr/fb/Kind17375Parsed.java +74 -0
- package/crates/native-ffi/react-native/android/src/main/java/nostr/fb/Kind17Parsed.java +81 -0
- package/crates/native-ffi/react-native/android/src/main/java/nostr/fb/Kind1Parsed.java +109 -0
- package/crates/native-ffi/react-native/android/src/main/java/nostr/fb/Kind20Parsed.java +107 -0
- package/crates/native-ffi/react-native/android/src/main/java/nostr/fb/Kind22Parsed.java +111 -0
- package/crates/native-ffi/react-native/android/src/main/java/nostr/fb/Kind30023Parsed.java +113 -0
- package/crates/native-ffi/react-native/android/src/main/java/nostr/fb/Kind3Parsed.java +59 -0
- package/crates/native-ffi/react-native/android/src/main/java/nostr/fb/Kind4Parsed.java +78 -0
- package/crates/native-ffi/react-native/android/src/main/java/nostr/fb/Kind6Parsed.java +53 -0
- package/crates/native-ffi/react-native/android/src/main/java/nostr/fb/Kind7374Parsed.java +66 -0
- package/crates/native-ffi/react-native/android/src/main/java/nostr/fb/Kind7375Parsed.java +79 -0
- package/crates/native-ffi/react-native/android/src/main/java/nostr/fb/Kind7376Parsed.java +100 -0
- package/crates/native-ffi/react-native/android/src/main/java/nostr/fb/Kind7Parsed.java +81 -0
- package/crates/native-ffi/react-native/android/src/main/java/nostr/fb/Kind8Parsed.java +78 -0
- package/crates/native-ffi/react-native/android/src/main/java/nostr/fb/Kind9321Parsed.java +117 -0
- package/crates/native-ffi/react-native/android/src/main/java/nostr/fb/Kind9735Parsed.java +119 -0
- package/crates/native-ffi/react-native/android/src/main/java/nostr/fb/KindFilterPipeConfig.java +60 -0
- package/crates/native-ffi/react-native/android/src/main/java/nostr/fb/LinkPreviewData.java +73 -0
- package/crates/native-ffi/react-native/android/src/main/java/nostr/fb/ListParsed.java +123 -0
- package/crates/native-ffi/react-native/android/src/main/java/nostr/fb/LiveActivityRef.java +72 -0
- package/crates/native-ffi/react-native/android/src/main/java/nostr/fb/LiveChatParticipant.java +61 -0
- package/crates/native-ffi/react-native/android/src/main/java/nostr/fb/LiveChatThreadRef.java +61 -0
- package/crates/native-ffi/react-native/android/src/main/java/nostr/fb/MainContent.java +20 -0
- package/crates/native-ffi/react-native/android/src/main/java/nostr/fb/MainMessage.java +57 -0
- package/crates/native-ffi/react-native/android/src/main/java/nostr/fb/MediaGroupData.java +58 -0
- package/crates/native-ffi/react-native/android/src/main/java/nostr/fb/MediaItem.java +58 -0
- package/crates/native-ffi/react-native/android/src/main/java/nostr/fb/Message.java +24 -0
- package/crates/native-ffi/react-native/android/src/main/java/nostr/fb/MessageType.java +19 -0
- package/crates/native-ffi/react-native/android/src/main/java/nostr/fb/MintInfo.java +65 -0
- package/crates/native-ffi/react-native/android/src/main/java/nostr/fb/MintProofs.java +66 -0
- package/crates/native-ffi/react-native/android/src/main/java/nostr/fb/MuteFilterPipeConfig.java +84 -0
- package/crates/native-ffi/react-native/android/src/main/java/nostr/fb/Nip07.java +43 -0
- package/crates/native-ffi/react-native/android/src/main/java/nostr/fb/Nip46Bunker.java +61 -0
- package/crates/native-ffi/react-native/android/src/main/java/nostr/fb/Nip46QR.java +61 -0
- package/crates/native-ffi/react-native/android/src/main/java/nostr/fb/NostrData.java +81 -0
- package/crates/native-ffi/react-native/android/src/main/java/nostr/fb/NostrEvent.java +95 -0
- package/crates/native-ffi/react-native/android/src/main/java/nostr/fb/NpubLimiterKey.java +15 -0
- package/crates/native-ffi/react-native/android/src/main/java/nostr/fb/NpubLimiterPipeConfig.java +64 -0
- package/crates/native-ffi/react-native/android/src/main/java/nostr/fb/P2PKWitness.java +57 -0
- package/crates/native-ffi/react-native/android/src/main/java/nostr/fb/ParsePipeConfig.java +43 -0
- package/crates/native-ffi/react-native/android/src/main/java/nostr/fb/ParsedData.java +39 -0
- package/crates/native-ffi/react-native/android/src/main/java/nostr/fb/ParsedDataUnion.java +35 -0
- package/crates/native-ffi/react-native/android/src/main/java/nostr/fb/ParsedEvent.java +108 -0
- package/crates/native-ffi/react-native/android/src/main/java/nostr/fb/Pipe.java +57 -0
- package/crates/native-ffi/react-native/android/src/main/java/nostr/fb/PipeConfig.java +23 -0
- package/crates/native-ffi/react-native/android/src/main/java/nostr/fb/PipelineConfig.java +59 -0
- package/crates/native-ffi/react-native/android/src/main/java/nostr/fb/PollOption.java +62 -0
- package/crates/native-ffi/react-native/android/src/main/java/nostr/fb/PollType.java +15 -0
- package/crates/native-ffi/react-native/android/src/main/java/nostr/fb/PreGenericParsed.java +213 -0
- package/crates/native-ffi/react-native/android/src/main/java/nostr/fb/PreParticipant.java +73 -0
- package/crates/native-ffi/react-native/android/src/main/java/nostr/fb/PreRefEvent.java +67 -0
- package/crates/native-ffi/react-native/android/src/main/java/nostr/fb/PrivateKey.java +55 -0
- package/crates/native-ffi/react-native/android/src/main/java/nostr/fb/ProfilePointer.java +64 -0
- package/crates/native-ffi/react-native/android/src/main/java/nostr/fb/Proof.java +90 -0
- package/crates/native-ffi/react-native/android/src/main/java/nostr/fb/ProofVerificationPipeConfig.java +52 -0
- package/crates/native-ffi/react-native/android/src/main/java/nostr/fb/Pubkey.java +55 -0
- package/crates/native-ffi/react-native/android/src/main/java/nostr/fb/Publish.java +80 -0
- package/crates/native-ffi/react-native/android/src/main/java/nostr/fb/Raw.java +55 -0
- package/crates/native-ffi/react-native/android/src/main/java/nostr/fb/ReactionType.java +17 -0
- package/crates/native-ffi/react-native/android/src/main/java/nostr/fb/RelayInfo.java +63 -0
- package/crates/native-ffi/react-native/android/src/main/java/nostr/fb/Request.java +134 -0
- package/crates/native-ffi/react-native/android/src/main/java/nostr/fb/SaveToDbPipeConfig.java +43 -0
- package/crates/native-ffi/react-native/android/src/main/java/nostr/fb/SerializeEventsPipeConfig.java +55 -0
- package/crates/native-ffi/react-native/android/src/main/java/nostr/fb/SetSigner.java +57 -0
- package/crates/native-ffi/react-native/android/src/main/java/nostr/fb/SignEvent.java +54 -0
- package/crates/native-ffi/react-native/android/src/main/java/nostr/fb/SignedEvent.java +54 -0
- package/crates/native-ffi/react-native/android/src/main/java/nostr/fb/SignerOp.java +19 -0
- package/crates/native-ffi/react-native/android/src/main/java/nostr/fb/SignerRequest.java +80 -0
- package/crates/native-ffi/react-native/android/src/main/java/nostr/fb/SignerResponse.java +64 -0
- package/crates/native-ffi/react-native/android/src/main/java/nostr/fb/SignerType.java +18 -0
- package/crates/native-ffi/react-native/android/src/main/java/nostr/fb/StringVec.java +57 -0
- package/crates/native-ffi/react-native/android/src/main/java/nostr/fb/Subscribe.java +72 -0
- package/crates/native-ffi/react-native/android/src/main/java/nostr/fb/SubscribeKind.java +19 -0
- package/crates/native-ffi/react-native/android/src/main/java/nostr/fb/SubscriptionConfig.java +95 -0
- package/crates/native-ffi/react-native/android/src/main/java/nostr/fb/Tag.java +64 -0
- package/crates/native-ffi/react-native/android/src/main/java/nostr/fb/Template.java +74 -0
- package/crates/native-ffi/react-native/android/src/main/java/nostr/fb/Unsubscribe.java +55 -0
- package/crates/native-ffi/react-native/android/src/main/java/nostr/fb/ValidProofs.java +59 -0
- package/crates/native-ffi/react-native/android/src/main/java/nostr/fb/VideoData.java +67 -0
- package/crates/native-ffi/react-native/android/src/main/java/nostr/fb/VideoVariant.java +102 -0
- package/crates/native-ffi/react-native/android/src/main/java/nostr/fb/Witness.java +17 -0
- package/crates/native-ffi/react-native/android/src/main/java/nostr/fb/WitnessString.java +54 -0
- package/crates/native-ffi/react-native/android/src/main/java/nostr/fb/WorkerMessage.java +74 -0
- package/crates/native-ffi/react-native/android/src/main/java/nostr/fb/ZapRequest.java +83 -0
- package/crates/native-ffi/react-native/ios/NipworkerReactNativeModule.h +18 -0
- package/crates/native-ffi/react-native/ios/NipworkerReactNativeModule.mm +263 -8
- package/dist/EngineManager.d.ts +1 -0
- package/dist/EngineManager.d.ts.map +1 -1
- package/dist/EngineManager.js +143 -137
- package/dist/NostrManager.d.ts +1 -0
- package/dist/NostrManager.d.ts.map +1 -1
- package/dist/NostrManager.js +49 -44
- package/dist/connections/index.js +87 -87
- package/dist/engine/index.js +119 -119
- package/dist/engine.d.ts.map +1 -1
- package/dist/hooks.d.ts +1 -1
- package/dist/hooks.d.ts.map +1 -1
- package/dist/hooks.js +27 -26
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/legacy.d.ts.map +1 -1
- package/dist/lib/ArrayBufferReader.d.ts +2 -1
- package/dist/lib/ArrayBufferReader.d.ts.map +1 -1
- package/dist/lib/BaseBackend.d.ts +5 -3
- package/dist/lib/BaseBackend.d.ts.map +1 -1
- package/dist/manager.d.ts +2 -6
- package/dist/manager.d.ts.map +1 -1
- package/dist/manager.js +10 -28
- package/dist/react-native.d.ts +33 -4
- package/dist/react-native.d.ts.map +1 -1
- package/dist/react-native.js +400 -122
- package/dist/scheduleMicrotask.js +58 -50
- package/package.json +13 -11
- package/swift/Package.swift +36 -0
- package/swift/README.md +438 -0
- package/swift/Sources/NipworkerSwift/ArrayBufferReader.swift +136 -0
- package/swift/Sources/NipworkerSwift/AuthSession.swift +24 -0
- package/swift/Sources/NipworkerSwift/FFI.swift +94 -0
- package/swift/Sources/NipworkerSwift/FlatBufferHelpers.swift +273 -0
- package/swift/Sources/NipworkerSwift/Generated/message_generated.swift +6530 -0
- package/swift/Sources/NipworkerSwift/Hooks.swift +300 -0
- package/swift/Sources/NipworkerSwift/Models.swift +156 -0
- package/swift/Sources/NipworkerSwift/NostrManager.swift +594 -0
- package/swift/Sources/NipworkerSwift/PublishTracker.swift +40 -0
- package/swift/Sources/NipworkerSwift/Subscription.swift +44 -0
- package/swift/Sources/NipworkerSwift/WorkerMessageView.swift +145 -0
- package/dist/NativeBackend.d.ts +0 -53
- package/dist/NativeBackend.d.ts.map +0 -1
- package/dist/NativeBackend.js +0 -464
- package/dist/native.d.ts +0 -29
- package/dist/native.d.ts.map +0 -1
- package/dist/native.js +0 -273
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
import Foundation
|
|
2
|
+
import FlatBuffers
|
|
3
|
+
|
|
4
|
+
public struct WorkerMessageView: Sendable {
|
|
5
|
+
public let data: Data
|
|
6
|
+
|
|
7
|
+
public init?(_ data: Data) {
|
|
8
|
+
guard data.count >= 4 else { return nil }
|
|
9
|
+
let bb = ByteBuffer(data: data)
|
|
10
|
+
let rootOffset = bb.read(def: Int32.self, position: 0)
|
|
11
|
+
guard rootOffset >= 0, Int(rootOffset) < data.count else { return nil }
|
|
12
|
+
self.data = data
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
public var message: nostr_fb_WorkerMessage {
|
|
16
|
+
let bb = ByteBuffer(data: data)
|
|
17
|
+
let rootOffset = bb.read(def: Int32.self, position: 0)
|
|
18
|
+
return nostr_fb_WorkerMessage(bb, o: rootOffset)
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
public var contentType: nostr_fb_Message {
|
|
22
|
+
message.contentType
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
public var messageType: nostr_fb_MessageType {
|
|
26
|
+
message.type
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
public var parsedEvent: nostr_fb_ParsedEvent? {
|
|
30
|
+
guard contentType == .parsedevent else { return nil }
|
|
31
|
+
return message.content(type: nostr_fb_ParsedEvent.self)
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
public var parsedType: nostr_fb_ParsedData? {
|
|
35
|
+
parsedEvent?.parsedType
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
public func parsedContent<T: FlatbuffersInitializable>(as type: T.Type, when parsedType: nostr_fb_ParsedData) -> T? {
|
|
39
|
+
guard let event = parsedEvent, event.parsedType == parsedType else { return nil }
|
|
40
|
+
return event.parsed(type: type)
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
public var kind0: nostr_fb_Kind0Parsed? {
|
|
44
|
+
parsedContent(as: nostr_fb_Kind0Parsed.self, when: .kind0parsed)
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
public var kind1: nostr_fb_Kind1Parsed? {
|
|
48
|
+
parsedContent(as: nostr_fb_Kind1Parsed.self, when: .kind1parsed)
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
public var kind3: nostr_fb_Kind3Parsed? {
|
|
52
|
+
parsedContent(as: nostr_fb_Kind3Parsed.self, when: .kind3parsed)
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
public var kind4: nostr_fb_Kind4Parsed? {
|
|
56
|
+
parsedContent(as: nostr_fb_Kind4Parsed.self, when: .kind4parsed)
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
public var kind6: nostr_fb_Kind6Parsed? {
|
|
60
|
+
parsedContent(as: nostr_fb_Kind6Parsed.self, when: .kind6parsed)
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
public var kind7: nostr_fb_Kind7Parsed? {
|
|
64
|
+
parsedContent(as: nostr_fb_Kind7Parsed.self, when: .kind7parsed)
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
public var kind17: nostr_fb_Kind17Parsed? {
|
|
68
|
+
parsedContent(as: nostr_fb_Kind17Parsed.self, when: .kind17parsed)
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
public var kind20: nostr_fb_Kind20Parsed? {
|
|
72
|
+
parsedContent(as: nostr_fb_Kind20Parsed.self, when: .kind20parsed)
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
public var kind22: nostr_fb_Kind22Parsed? {
|
|
76
|
+
parsedContent(as: nostr_fb_Kind22Parsed.self, when: .kind22parsed)
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
public var kind1111: nostr_fb_Kind1111Parsed? {
|
|
80
|
+
parsedContent(as: nostr_fb_Kind1111Parsed.self, when: .kind1111parsed)
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
public var kind1311: nostr_fb_Kind1311Parsed? {
|
|
84
|
+
parsedContent(as: nostr_fb_Kind1311Parsed.self, when: .kind1311parsed)
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
public var kind1018: nostr_fb_Kind1018Parsed? {
|
|
88
|
+
parsedContent(as: nostr_fb_Kind1018Parsed.self, when: .kind1018parsed)
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
public var kind1068: nostr_fb_Kind1068Parsed? {
|
|
92
|
+
parsedContent(as: nostr_fb_Kind1068Parsed.self, when: .kind1068parsed)
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
public var kind10002: nostr_fb_Kind10002Parsed? {
|
|
96
|
+
parsedContent(as: nostr_fb_Kind10002Parsed.self, when: .kind10002parsed)
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
public var kind10019: nostr_fb_Kind10019Parsed? {
|
|
100
|
+
parsedContent(as: nostr_fb_Kind10019Parsed.self, when: .kind10019parsed)
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
public var kind17375: nostr_fb_Kind17375Parsed? {
|
|
104
|
+
parsedContent(as: nostr_fb_Kind17375Parsed.self, when: .kind17375parsed)
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
public var kind7374: nostr_fb_Kind7374Parsed? {
|
|
108
|
+
parsedContent(as: nostr_fb_Kind7374Parsed.self, when: .kind7374parsed)
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
public var kind7375: nostr_fb_Kind7375Parsed? {
|
|
112
|
+
parsedContent(as: nostr_fb_Kind7375Parsed.self, when: .kind7375parsed)
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
public var kind7376: nostr_fb_Kind7376Parsed? {
|
|
116
|
+
parsedContent(as: nostr_fb_Kind7376Parsed.self, when: .kind7376parsed)
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
public var kind9321: nostr_fb_Kind9321Parsed? {
|
|
120
|
+
parsedContent(as: nostr_fb_Kind9321Parsed.self, when: .kind9321parsed)
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
public var kind9735: nostr_fb_Kind9735Parsed? {
|
|
124
|
+
parsedContent(as: nostr_fb_Kind9735Parsed.self, when: .kind9735parsed)
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
public var kind30023: nostr_fb_Kind30023Parsed? {
|
|
128
|
+
parsedContent(as: nostr_fb_Kind30023Parsed.self, when: .kind30023parsed)
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
public var nostrEvent: nostr_fb_NostrEvent? {
|
|
132
|
+
guard contentType == .nostrevent else { return nil }
|
|
133
|
+
return message.content(type: nostr_fb_NostrEvent.self)
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
public var raw: nostr_fb_Raw? {
|
|
137
|
+
guard contentType == .raw else { return nil }
|
|
138
|
+
return message.content(type: nostr_fb_Raw.self)
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
public var countResponse: nostr_fb_CountResponse? {
|
|
142
|
+
guard contentType == .countresponse else { return nil }
|
|
143
|
+
return message.content(type: nostr_fb_CountResponse.self)
|
|
144
|
+
}
|
|
145
|
+
}
|
package/dist/NativeBackend.d.ts
DELETED
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
import { BaseBackend, StorageAdapter } from './lib/BaseBackend';
|
|
2
|
-
import { NostrManagerConfig, RequestObject, SubscriptionConfig } from './types';
|
|
3
|
-
import { EventTemplate, NostrEvent } from 'nostr-tools';
|
|
4
|
-
|
|
5
|
-
export type NativeRuntimeBridge = {
|
|
6
|
-
name: string;
|
|
7
|
-
eventName: string;
|
|
8
|
-
storage: StorageAdapter;
|
|
9
|
-
getModule(): any;
|
|
10
|
-
getEventEmitter(): any;
|
|
11
|
-
};
|
|
12
|
-
export declare const lynxNativeBridge: NativeRuntimeBridge;
|
|
13
|
-
/**
|
|
14
|
-
* NativeBackend implements the same public interface as EngineManager / NostrManager,
|
|
15
|
-
* but communicates with the native libnipworker_native_ffi via a Lynx native module.
|
|
16
|
-
*
|
|
17
|
-
* This is a skeleton implementation for mobile (iOS / Android / HarmonyOS) consumption.
|
|
18
|
-
*/
|
|
19
|
-
export declare class NativeBackend extends BaseBackend {
|
|
20
|
-
private nativeModule;
|
|
21
|
-
private _signCB;
|
|
22
|
-
private instanceId;
|
|
23
|
-
private eventEmitter;
|
|
24
|
-
private eventListener;
|
|
25
|
-
private deinitialized;
|
|
26
|
-
private runtimeBridge;
|
|
27
|
-
constructor(_config?: NostrManagerConfig, runtimeBridge?: NativeRuntimeBridge);
|
|
28
|
-
private setupVisibilityTracking;
|
|
29
|
-
protected wakeNative(): void;
|
|
30
|
-
isDeinitialized(): boolean;
|
|
31
|
-
private handleNativeMessage;
|
|
32
|
-
private handleDirectResponse;
|
|
33
|
-
private handleCryptoMessage;
|
|
34
|
-
private postMessage;
|
|
35
|
-
private closeSubscription;
|
|
36
|
-
subscribe(subscriptionId: string, requests: RequestObject[], options: SubscriptionConfig): ArrayBuffer;
|
|
37
|
-
publish(publish_id: string, event: NostrEvent, defaultRelays?: string[], optimisticSubIds?: string[]): ArrayBuffer;
|
|
38
|
-
setSigner(name: string, payload?: string | {
|
|
39
|
-
url: string;
|
|
40
|
-
clientSecret: string;
|
|
41
|
-
}): void;
|
|
42
|
-
signEvent(event: EventTemplate, cb: (event: NostrEvent) => void): void;
|
|
43
|
-
getPublicKey(): void;
|
|
44
|
-
protected onLogout(): void;
|
|
45
|
-
cleanup(): void;
|
|
46
|
-
/**
|
|
47
|
-
* Explicitly tear down the native engine. Call this when the app is shutting
|
|
48
|
-
* down or the backend is no longer needed.
|
|
49
|
-
*/
|
|
50
|
-
deinit(): void;
|
|
51
|
-
}
|
|
52
|
-
export declare function getOrCreateNativeBackend(config?: NostrManagerConfig): NativeBackend;
|
|
53
|
-
//# sourceMappingURL=NativeBackend.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"NativeBackend.d.ts","sourceRoot":"","sources":["../src/NativeBackend.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,WAAW,EAAE,KAAK,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACvE,OAAO,KAAK,EAAE,kBAAkB,EAAE,aAAa,EAAE,kBAAkB,EAAE,MAAM,WAAW,CAAC;AACvF,OAAO,KAAK,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AA0E7D,MAAM,MAAM,mBAAmB,GAAG;IACjC,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,cAAc,CAAC;IACxB,SAAS,IAAI,GAAG,CAAC;IACjB,eAAe,IAAI,GAAG,CAAC;CACvB,CAAC;AAiJF,eAAO,MAAM,gBAAgB,EAAE,mBAM9B,CAAC;AAEF;;;;;GAKG;AACH,qBAAa,aAAc,SAAQ,WAAW;IAC7C,OAAO,CAAC,YAAY,CAAM;IAC1B,OAAO,CAAC,OAAO,CAA8B;IAC7C,OAAO,CAAC,UAAU,CAAS;IAC3B,OAAO,CAAC,YAAY,CAAM;IAC1B,OAAO,CAAC,aAAa,CAAqC;IAC1D,OAAO,CAAC,aAAa,CAAS;IAC9B,OAAO,CAAC,aAAa,CAAsB;gBAG1C,OAAO,GAAE,kBAAuB,EAChC,aAAa,GAAE,mBAAsC;IA6HtD,OAAO,CAAC,uBAAuB;IAa/B,SAAS,CAAC,UAAU,IAAI,IAAI;IAM5B,eAAe,IAAI,OAAO;IAI1B,OAAO,CAAC,mBAAmB;IAyE3B,OAAO,CAAC,oBAAoB;IAoD5B,OAAO,CAAC,mBAAmB;IAwC3B,OAAO,CAAC,WAAW;IAMnB,OAAO,CAAC,iBAAiB;IASzB,SAAS,CACR,cAAc,EAAE,MAAM,EACtB,QAAQ,EAAE,aAAa,EAAE,EACzB,OAAO,EAAE,kBAAkB,GACzB,WAAW;IAsEd,OAAO,CACN,UAAU,EAAE,MAAM,EAClB,KAAK,EAAE,UAAU,EACjB,aAAa,GAAE,MAAM,EAAO,EAC5B,gBAAgB,CAAC,EAAE,MAAM,EAAE,GACzB,WAAW;IAyBd,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG;QAAE,GAAG,EAAE,MAAM,CAAC;QAAC,YAAY,EAAE,MAAM,CAAA;KAAE,GAAG,IAAI;IA8CvF,SAAS,CAAC,KAAK,EAAE,aAAa,EAAE,EAAE,EAAE,CAAC,KAAK,EAAE,UAAU,KAAK,IAAI;IAgB/D,YAAY;IAQZ,SAAS,CAAC,QAAQ,IAAI,IAAI;IAI1B,OAAO,IAAI,IAAI;IAkBf;;;OAGG;IACH,MAAM,IAAI,IAAI;CAgBd;AAED,wBAAgB,wBAAwB,CAAC,MAAM,GAAE,kBAAuB,GAAG,aAAa,CAMvF"}
|
package/dist/NativeBackend.js
DELETED
|
@@ -1,464 +0,0 @@
|
|
|
1
|
-
import * as g from "flatbuffers";
|
|
2
|
-
import { s as D, A as w } from "./scheduleMicrotask.js";
|
|
3
|
-
import { _ as O, Z as E, g as p, M as b, w as L, t as k, u as m, i as R, r as z, E as V, H as j, V as F, T as G, X as B, D as K, J as A, Q as P, l as J, n as W, O as H, d as $ } from "./BaseBackend.js";
|
|
4
|
-
import { aT as S, bn as Q, bm as X, bo as _ } from "./message-type.js";
|
|
5
|
-
import { W as x, P as Y, S as q, R as Z } from "./worker-message.js";
|
|
6
|
-
import { s as ee } from "./manager.js";
|
|
7
|
-
const N = "__nipworker_native_backend_state", te = "NipworkerEvent";
|
|
8
|
-
function M() {
|
|
9
|
-
const s = globalThis;
|
|
10
|
-
return s[N] || (s[N] = {
|
|
11
|
-
instance: void 0,
|
|
12
|
-
activeListener: void 0,
|
|
13
|
-
instances: []
|
|
14
|
-
}), s[N];
|
|
15
|
-
}
|
|
16
|
-
const ne = {
|
|
17
|
-
getItem(s) {
|
|
18
|
-
var _a, _b, _c;
|
|
19
|
-
return typeof localStorage < "u" ? localStorage.getItem(s) : ((_c = (_b = (_a = globalThis.lynx) == null ? void 0 : _a.getStorageSync) == null ? void 0 : _b.call(_a, { key: s })) == null ? void 0 : _c.data) ?? null;
|
|
20
|
-
},
|
|
21
|
-
setItem(s, e) {
|
|
22
|
-
var _a, _b;
|
|
23
|
-
if (typeof localStorage < "u") {
|
|
24
|
-
localStorage.setItem(s, e);
|
|
25
|
-
return;
|
|
26
|
-
}
|
|
27
|
-
(_b = (_a = globalThis.lynx) == null ? void 0 : _a.setStorageSync) == null ? void 0 : _b.call(_a, { key: s, data: e });
|
|
28
|
-
},
|
|
29
|
-
removeItem(s) {
|
|
30
|
-
var _a, _b;
|
|
31
|
-
if (typeof localStorage < "u") {
|
|
32
|
-
localStorage.removeItem(s);
|
|
33
|
-
return;
|
|
34
|
-
}
|
|
35
|
-
(_b = (_a = globalThis.lynx) == null ? void 0 : _a.removeStorageSync) == null ? void 0 : _b.call(_a, { key: s });
|
|
36
|
-
}
|
|
37
|
-
};
|
|
38
|
-
function C(s) {
|
|
39
|
-
if (typeof atob == "function") {
|
|
40
|
-
const n = atob(s), o = new Uint8Array(n.length);
|
|
41
|
-
for (let r = 0; r < n.length; r++)
|
|
42
|
-
o[r] = n.charCodeAt(r);
|
|
43
|
-
return o;
|
|
44
|
-
}
|
|
45
|
-
const e = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/", a = /* @__PURE__ */ new Map();
|
|
46
|
-
for (let n = 0; n < e.length; n++)
|
|
47
|
-
a.set(e.charAt(n), n);
|
|
48
|
-
const t = s.replace(/=+$/, ""), c = t.length, i = new Uint8Array(Math.floor(c * 3 / 4));
|
|
49
|
-
let l = 0;
|
|
50
|
-
for (let n = 0; n < c; n += 4) {
|
|
51
|
-
const o = t[n] ?? "", r = t[n + 1] ?? "", u = t[n + 2], h = t[n + 3], v = a.get(o) ?? 0, f = a.get(r) ?? 0, y = u === void 0 ? 0 : a.get(u) ?? 0, d = h === void 0 ? 0 : a.get(h) ?? 0;
|
|
52
|
-
i[l++] = v << 2 | f >> 4, u !== void 0 && (i[l++] = (f & 15) << 4 | y >> 2), h !== void 0 && (i[l++] = (y & 3) << 6 | d);
|
|
53
|
-
}
|
|
54
|
-
return i.subarray(0, l);
|
|
55
|
-
}
|
|
56
|
-
function I(s) {
|
|
57
|
-
return s instanceof Uint8Array ? s : s instanceof ArrayBuffer ? new Uint8Array(s) : ArrayBuffer.isView(s) ? new Uint8Array(s.buffer, s.byteOffset, s.byteLength) : Array.isArray(s) ? new Uint8Array(s) : typeof s == "string" ? C(s) : !s || typeof s != "object" || s.v !== 1 || typeof s.data > "u" ? null : s.encoding === "bytes" ? I(s.data) : s.encoding === "base64" && typeof s.data == "string" ? C(s.data) : null;
|
|
58
|
-
}
|
|
59
|
-
function ie() {
|
|
60
|
-
var _a, _b, _c, _d, _e, _f;
|
|
61
|
-
let s = typeof NativeModules < "u" && (NativeModules == null ? void 0 : NativeModules.NipworkerLynxModule) || ((_c = (_b = (_a = globalThis.lynx) == null ? void 0 : _a.getNativeModules) == null ? void 0 : _b.call(_a)) == null ? void 0 : _c.NipworkerLynxModule) || ((_d = globalThis.NativeModules) == null ? void 0 : _d.NipworkerLynxModule);
|
|
62
|
-
if (!s)
|
|
63
|
-
try {
|
|
64
|
-
const e = (_f = (_e = globalThis.lynx) == null ? void 0 : _e.getNativeApp) == null ? void 0 : _f.call(_e);
|
|
65
|
-
e && e.NativeModules && (s = e.NativeModules.NipworkerLynxModule);
|
|
66
|
-
} catch {
|
|
67
|
-
}
|
|
68
|
-
if (!s)
|
|
69
|
-
throw new Error(
|
|
70
|
-
"[NativeBackend] NipworkerLynxModule not found. Ensure the native module is registered."
|
|
71
|
-
);
|
|
72
|
-
return s;
|
|
73
|
-
}
|
|
74
|
-
function se() {
|
|
75
|
-
var _a, _b, _c;
|
|
76
|
-
let s = (_b = (_a = globalThis.lynx) == null ? void 0 : _a.getJSModule) == null ? void 0 : _b.call(_a, "GlobalEventEmitter");
|
|
77
|
-
if (!s && typeof lynx < "u" && (s = (_c = lynx.getJSModule) == null ? void 0 : _c.call(lynx, "GlobalEventEmitter")), !s)
|
|
78
|
-
throw new Error(
|
|
79
|
-
"[NativeBackend] GlobalEventEmitter not found. Native events will not be received."
|
|
80
|
-
);
|
|
81
|
-
return s;
|
|
82
|
-
}
|
|
83
|
-
const ae = {
|
|
84
|
-
name: "lynx",
|
|
85
|
-
eventName: te,
|
|
86
|
-
storage: ne,
|
|
87
|
-
getModule: ie,
|
|
88
|
-
getEventEmitter: se
|
|
89
|
-
};
|
|
90
|
-
class re extends O {
|
|
91
|
-
constructor(e = {}, a = ae) {
|
|
92
|
-
var _a, _b, _c, _d, _e, _f;
|
|
93
|
-
super(a.storage), this._signCB = (l) => {
|
|
94
|
-
}, this.eventListener = null, this.deinitialized = false, this.runtimeBridge = a, this.instanceId = Math.random().toString(36).slice(2, 8);
|
|
95
|
-
const t = M();
|
|
96
|
-
t.instances.push({
|
|
97
|
-
instanceId: this.instanceId,
|
|
98
|
-
stack: new Error().stack,
|
|
99
|
-
t: Date.now()
|
|
100
|
-
}), this.nativeModule = a.getModule(), typeof globalThis < "u" && (globalThis.__nipworker_native_diag = {
|
|
101
|
-
callbackCount: 0,
|
|
102
|
-
lastCallbackLen: 0,
|
|
103
|
-
lastCallbackTime: 0,
|
|
104
|
-
handleNativeMessageCount: 0,
|
|
105
|
-
handleNativeMessageErrors: 0,
|
|
106
|
-
subscriptionCount: 0,
|
|
107
|
-
publishCount: 0
|
|
108
|
-
});
|
|
109
|
-
const c = {
|
|
110
|
-
runtime: a.name,
|
|
111
|
-
hasLynx: !!globalThis.lynx,
|
|
112
|
-
hasGetJSModule: !!((_a = globalThis.lynx) == null ? void 0 : _a.getJSModule),
|
|
113
|
-
hasGlobalEventEmitter: false,
|
|
114
|
-
hasNativeModulesGlobal: !!globalThis.NativeModules,
|
|
115
|
-
hasNativeModulesFn: !!((_b = globalThis.lynx) == null ? void 0 : _b.getNativeModules),
|
|
116
|
-
hasNipworkerModule: !!((_c = globalThis.NativeModules) == null ? void 0 : _c.NipworkerLynxModule) || !!((_f = (_e = (_d = globalThis.lynx) == null ? void 0 : _d.getNativeModules) == null ? void 0 : _e.call(_d)) == null ? void 0 : _f.NipworkerLynxModule),
|
|
117
|
-
emitterType: "unknown",
|
|
118
|
-
emitterHasAddListener: false
|
|
119
|
-
};
|
|
120
|
-
let i;
|
|
121
|
-
try {
|
|
122
|
-
i = a.getEventEmitter(), c.hasGlobalEventEmitter = !!i, c.emitterType = typeof i, c.emitterHasAddListener = typeof (i == null ? void 0 : i.addListener) == "function";
|
|
123
|
-
} catch (l) {
|
|
124
|
-
c.emitterType = "error:" + String(l);
|
|
125
|
-
}
|
|
126
|
-
if (typeof globalThis < "u") {
|
|
127
|
-
const l = globalThis;
|
|
128
|
-
l.__nipworker_native_probe = c, (l.__nipworker_trace = l.__nipworker_trace || []).push({
|
|
129
|
-
where: "NativeBackend constructor probe",
|
|
130
|
-
probe: c,
|
|
131
|
-
t: Date.now()
|
|
132
|
-
});
|
|
133
|
-
}
|
|
134
|
-
if (!i || typeof i.addListener != "function")
|
|
135
|
-
throw new Error(
|
|
136
|
-
`[NativeBackend] ${a.name} event emitter unavailable: ${c.emitterType}`
|
|
137
|
-
);
|
|
138
|
-
if (this.eventEmitter = i, this.eventListener = (l) => {
|
|
139
|
-
if (this.deinitialized) return;
|
|
140
|
-
const n = Array.isArray(l) ? l[0] : l;
|
|
141
|
-
let o;
|
|
142
|
-
try {
|
|
143
|
-
const r = I(n);
|
|
144
|
-
if (!r) {
|
|
145
|
-
console.warn("[NativeBackend] Ignoring malformed NipworkerEvent", n);
|
|
146
|
-
return;
|
|
147
|
-
}
|
|
148
|
-
o = r;
|
|
149
|
-
} catch (r) {
|
|
150
|
-
console.error("[NativeBackend] Failed to decode native event payload", r);
|
|
151
|
-
return;
|
|
152
|
-
}
|
|
153
|
-
if (typeof globalThis < "u") {
|
|
154
|
-
const r = globalThis.__nipworker_native_diag;
|
|
155
|
-
r && (r.callbackCount++, r.lastCallbackLen = o.length, r.lastCallbackTime = Date.now());
|
|
156
|
-
}
|
|
157
|
-
try {
|
|
158
|
-
this.handleNativeMessage(o);
|
|
159
|
-
} catch (r) {
|
|
160
|
-
if (console.error("[NativeBackend] Failed to handle native message", r), typeof globalThis < "u") {
|
|
161
|
-
const u = globalThis.__nipworker_native_diag;
|
|
162
|
-
u && u.handleNativeMessageErrors++;
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
}, t.activeListener)
|
|
166
|
-
try {
|
|
167
|
-
t.activeListener.emitter.removeListener(
|
|
168
|
-
t.activeListener.eventName,
|
|
169
|
-
t.activeListener.listener
|
|
170
|
-
), console.warn(
|
|
171
|
-
"[NativeBackend] Removed stale NipworkerEvent listener from instanceId=" + t.activeListener.instanceId
|
|
172
|
-
);
|
|
173
|
-
} catch (l) {
|
|
174
|
-
console.warn("[NativeBackend] Failed to remove stale NipworkerEvent listener", l);
|
|
175
|
-
}
|
|
176
|
-
i.addListener(a.eventName, this.eventListener), t.activeListener = {
|
|
177
|
-
emitter: i,
|
|
178
|
-
listener: this.eventListener,
|
|
179
|
-
instanceId: this.instanceId,
|
|
180
|
-
eventName: a.eventName
|
|
181
|
-
}, t.instance = this, this.nativeModule.init(e), this.setupVisibilityTracking(), D(() => this.restoreSession()), ee(this);
|
|
182
|
-
}
|
|
183
|
-
setupVisibilityTracking() {
|
|
184
|
-
if (typeof document > "u") return;
|
|
185
|
-
let e = false;
|
|
186
|
-
document.addEventListener("visibilitychange", () => {
|
|
187
|
-
document.hidden ? e = true : e && (e = false, this.wakeNative());
|
|
188
|
-
});
|
|
189
|
-
}
|
|
190
|
-
wakeNative() {
|
|
191
|
-
var _a;
|
|
192
|
-
typeof ((_a = this.nativeModule) == null ? void 0 : _a.wake) == "function" && this.nativeModule.wake();
|
|
193
|
-
}
|
|
194
|
-
isDeinitialized() {
|
|
195
|
-
return this.deinitialized;
|
|
196
|
-
}
|
|
197
|
-
handleNativeMessage(e) {
|
|
198
|
-
if (typeof globalThis < "u") {
|
|
199
|
-
const u = globalThis.__nipworker_native_diag;
|
|
200
|
-
u && u.handleNativeMessageCount++;
|
|
201
|
-
}
|
|
202
|
-
if (e.length < 8) {
|
|
203
|
-
console.warn("[NativeBackend] Ignoring malformed native message: data too short");
|
|
204
|
-
return;
|
|
205
|
-
}
|
|
206
|
-
const a = new DataView(e.buffer, e.byteOffset, e.byteLength);
|
|
207
|
-
let t = 0;
|
|
208
|
-
const c = a.getUint32(t, true);
|
|
209
|
-
if (t += 4, t + c > e.byteLength) {
|
|
210
|
-
console.warn("[NativeBackend] Ignoring malformed native message: subId exceeds buffer");
|
|
211
|
-
return;
|
|
212
|
-
}
|
|
213
|
-
const i = new TextDecoder().decode(e.subarray(t, t + c));
|
|
214
|
-
if (t += c, t + 4 > e.byteLength) {
|
|
215
|
-
console.warn("[NativeBackend] Ignoring malformed native message: missing payload length");
|
|
216
|
-
return;
|
|
217
|
-
}
|
|
218
|
-
const l = a.getUint32(t, true);
|
|
219
|
-
if (t += 4, t + l > e.byteLength) {
|
|
220
|
-
console.warn("[NativeBackend] Ignoring malformed native message: payload exceeds buffer");
|
|
221
|
-
return;
|
|
222
|
-
}
|
|
223
|
-
const n = e.subarray(t, t + l);
|
|
224
|
-
if (i === "crypto") {
|
|
225
|
-
this.handleCryptoMessage(n);
|
|
226
|
-
return;
|
|
227
|
-
}
|
|
228
|
-
if (i === "") {
|
|
229
|
-
this.handleDirectResponse(n);
|
|
230
|
-
return;
|
|
231
|
-
}
|
|
232
|
-
if (typeof globalThis < "u") {
|
|
233
|
-
const u = globalThis.__nipworker_native_diag;
|
|
234
|
-
u && (u.subscriptionCount = this.subscriptions.size);
|
|
235
|
-
}
|
|
236
|
-
const o = this.subscriptions.get(i);
|
|
237
|
-
if (o) {
|
|
238
|
-
const u = o.buffer;
|
|
239
|
-
w.writePayload(u, n, i) ? this.dispatch(`subscription:${i}`, i) : this.closeSubscription(i);
|
|
240
|
-
return;
|
|
241
|
-
}
|
|
242
|
-
const r = this.publishes.get(i);
|
|
243
|
-
if (r) {
|
|
244
|
-
w.writePayload(r.buffer, n, i) ? this.dispatch(`publish:${i}`, i) : this.publishes.delete(i);
|
|
245
|
-
return;
|
|
246
|
-
}
|
|
247
|
-
if (typeof globalThis < "u") {
|
|
248
|
-
const u = globalThis.__nipworker_native_diag;
|
|
249
|
-
u && (u.lastMissingSubId = i);
|
|
250
|
-
}
|
|
251
|
-
}
|
|
252
|
-
handleDirectResponse(e) {
|
|
253
|
-
var _a;
|
|
254
|
-
if (e.length < 4) return;
|
|
255
|
-
const t = new DataView(e.buffer, e.byteOffset, e.byteLength).getUint32(0, true);
|
|
256
|
-
if (e.length < 4 + t) return;
|
|
257
|
-
const c = new g.ByteBuffer(e.subarray(4, 4 + t)), i = x.getRootAsWorkerMessage(c), l = i.type();
|
|
258
|
-
if (l === S.Pubkey) {
|
|
259
|
-
const n = i.content(new Y()), o = n ? n.pubkey() : null;
|
|
260
|
-
if (o) {
|
|
261
|
-
this.activePubkey = o;
|
|
262
|
-
const r = ((_a = this._pendingSession) == null ? void 0 : _a.type) === "privkey" ? this._pendingSession.payload : void 0;
|
|
263
|
-
this._pendingSession && (this.saveSession(o, this._pendingSession.type, this._pendingSession.payload), this._pendingSession = null), this.dispatch("auth", { pubkey: this.activePubkey, hasSigner: true, secretKey: r });
|
|
264
|
-
} else
|
|
265
|
-
this.dispatch("auth", { pubkey: null, hasSigner: false });
|
|
266
|
-
} else if (l === S.SignedEvent) {
|
|
267
|
-
const n = i.content(new q()), o = n ? n.event() : null;
|
|
268
|
-
if (o) {
|
|
269
|
-
const r = {
|
|
270
|
-
id: o.id() || "",
|
|
271
|
-
pubkey: o.pubkey() || "",
|
|
272
|
-
created_at: o.createdAt(),
|
|
273
|
-
kind: o.kind(),
|
|
274
|
-
tags: [],
|
|
275
|
-
content: o.content() || "",
|
|
276
|
-
sig: o.sig() || ""
|
|
277
|
-
};
|
|
278
|
-
for (let u = 0; u < o.tagsLength(); u++) {
|
|
279
|
-
const h = o.tags(u, new Q());
|
|
280
|
-
if (h) {
|
|
281
|
-
const v = [];
|
|
282
|
-
for (let f = 0; f < h.itemsLength(); f++) {
|
|
283
|
-
const y = h.items(f);
|
|
284
|
-
y !== null && v.push(y);
|
|
285
|
-
}
|
|
286
|
-
r.tags.push(v);
|
|
287
|
-
}
|
|
288
|
-
}
|
|
289
|
-
this._signCB(r);
|
|
290
|
-
}
|
|
291
|
-
}
|
|
292
|
-
}
|
|
293
|
-
handleCryptoMessage(e) {
|
|
294
|
-
var _a;
|
|
295
|
-
const a = new g.ByteBuffer(e), t = x.getRootAsWorkerMessage(a);
|
|
296
|
-
if (t.type() !== S.Raw) return;
|
|
297
|
-
const i = t.content(new Z()), l = i ? i.raw() : null;
|
|
298
|
-
if (l)
|
|
299
|
-
try {
|
|
300
|
-
const n = JSON.parse(l);
|
|
301
|
-
if (n.op === "get_public_key" || n.op === "set_signer") {
|
|
302
|
-
const o = ((_a = this._pendingSession) == null ? void 0 : _a.type) === "privkey" ? this._pendingSession.payload : void 0;
|
|
303
|
-
if (n.result && (this.activePubkey = n.result, this._pendingSession)) {
|
|
304
|
-
const r = this._pendingSession.type === "nip46" && typeof n.bunker_url == "string" && n.bunker_url.startsWith("bunker://") && this._pendingSession.payload && typeof this._pendingSession.payload == "object" ? { ...this._pendingSession.payload, url: n.bunker_url } : this._pendingSession.payload;
|
|
305
|
-
this.saveSession(this.activePubkey, this._pendingSession.type, r), this._pendingSession = null;
|
|
306
|
-
}
|
|
307
|
-
this.dispatch("auth", { pubkey: this.activePubkey, hasSigner: !!n.result, secretKey: o });
|
|
308
|
-
} else if (n.op === "sign_event" && n.result) {
|
|
309
|
-
const o = JSON.parse(n.result);
|
|
310
|
-
this._signCB(o);
|
|
311
|
-
} else n.error && console.warn("[NativeBackend] Crypto error:", n.error);
|
|
312
|
-
} catch (n) {
|
|
313
|
-
console.warn("[NativeBackend] Failed to parse crypto raw message:", n);
|
|
314
|
-
}
|
|
315
|
-
}
|
|
316
|
-
postMessage(e) {
|
|
317
|
-
this.nativeModule.handleMessage(e.slice().buffer);
|
|
318
|
-
}
|
|
319
|
-
closeSubscription(e) {
|
|
320
|
-
const a = new E(this.textEncoder.encode(e)), t = new p(b.Unsubscribe, a), c = new g.Builder(1024);
|
|
321
|
-
c.finish(t.pack(c)), this.postMessage(c.asUint8Array()), this.subscriptions.delete(e);
|
|
322
|
-
}
|
|
323
|
-
subscribe(e, a, t) {
|
|
324
|
-
const c = e, i = this.subscriptions.get(c);
|
|
325
|
-
if (i)
|
|
326
|
-
return i.refCount++, i.buffer;
|
|
327
|
-
const l = a.reduce((d, T) => d + (T.limit || 100), 0), n = w.calculateBufferSize(l, t.bytesPerEvent), o = new ArrayBuffer(n);
|
|
328
|
-
w.initializeBuffer(o), this.subscriptions.set(c, { buffer: o, options: t, refCount: 1 });
|
|
329
|
-
const r = t.pipeline !== void 0 ? new L(t.pipeline) : new L([
|
|
330
|
-
new k(m.MuteFilterPipeConfig, new R()),
|
|
331
|
-
new k(m.ParsePipeConfig, new z()),
|
|
332
|
-
new k(m.SaveToDbPipeConfig, new V()),
|
|
333
|
-
new k(m.SerializeEventsPipeConfig, new j(c))
|
|
334
|
-
]), u = new F(
|
|
335
|
-
r,
|
|
336
|
-
t.closeOnEose,
|
|
337
|
-
t.cacheFirst,
|
|
338
|
-
t.timeoutMs ? BigInt(t.timeoutMs) : void 0,
|
|
339
|
-
t.maxEvents,
|
|
340
|
-
t.skipCache,
|
|
341
|
-
t.force,
|
|
342
|
-
t.bytesPerEvent,
|
|
343
|
-
t.isSlow,
|
|
344
|
-
t.pagination ? this.textEncoder.encode(t.pagination) : null
|
|
345
|
-
), h = new G(
|
|
346
|
-
this.textEncoder.encode(c),
|
|
347
|
-
a.map(
|
|
348
|
-
(d) => new X(
|
|
349
|
-
d.ids,
|
|
350
|
-
d.authors,
|
|
351
|
-
d.kinds,
|
|
352
|
-
Object.entries(d.tags || {}).flatMap(
|
|
353
|
-
([T, U]) => new _([T, ...U])
|
|
354
|
-
),
|
|
355
|
-
d.limit,
|
|
356
|
-
d.since,
|
|
357
|
-
d.until,
|
|
358
|
-
d.search ? this.textEncoder.encode(d.search) : null,
|
|
359
|
-
d.relays,
|
|
360
|
-
d.closeOnEOSE,
|
|
361
|
-
d.cacheFirst,
|
|
362
|
-
d.noCache
|
|
363
|
-
)
|
|
364
|
-
),
|
|
365
|
-
u
|
|
366
|
-
), v = new p(b.Subscribe, h), f = new g.Builder(2048);
|
|
367
|
-
f.finish(v.pack(f));
|
|
368
|
-
const y = f.asUint8Array();
|
|
369
|
-
return this.postMessage(y), o;
|
|
370
|
-
}
|
|
371
|
-
publish(e, a, t = [], c) {
|
|
372
|
-
const i = new ArrayBuffer(3072);
|
|
373
|
-
w.initializeBuffer(i);
|
|
374
|
-
const l = new B(
|
|
375
|
-
a.kind,
|
|
376
|
-
a.created_at,
|
|
377
|
-
this.textEncoder.encode(a.content),
|
|
378
|
-
a.tags.map((h) => new _(h)) || []
|
|
379
|
-
), n = new K(
|
|
380
|
-
this.textEncoder.encode(e),
|
|
381
|
-
l,
|
|
382
|
-
t,
|
|
383
|
-
c || []
|
|
384
|
-
), o = new p(b.Publish, n), r = new g.Builder(2048);
|
|
385
|
-
r.finish(o.pack(r));
|
|
386
|
-
const u = r.asUint8Array();
|
|
387
|
-
return this.postMessage(u), this.publishes.set(e, { buffer: i }), i;
|
|
388
|
-
}
|
|
389
|
-
setSigner(e, a) {
|
|
390
|
-
switch (this._pendingSession = { type: e, payload: a }, e) {
|
|
391
|
-
case "pubkey":
|
|
392
|
-
this.activePubkey = a, this.saveSession(this.activePubkey, "pubkey", a), this._pendingSession = null, this.dispatch("auth", { pubkey: this.activePubkey, hasSigner: false });
|
|
393
|
-
break;
|
|
394
|
-
case "privkey": {
|
|
395
|
-
this.nativeModule.setPrivateKey(a), this.getPublicKey();
|
|
396
|
-
break;
|
|
397
|
-
}
|
|
398
|
-
case "nip07":
|
|
399
|
-
console.warn("[NativeBackend] NIP-07 is not supported in the native backend"), this.dispatch("auth", { pubkey: null, hasSigner: false });
|
|
400
|
-
break;
|
|
401
|
-
case "nip46": {
|
|
402
|
-
const t = a, c = (t == null ? void 0 : t.url) || "", i = t == null ? void 0 : t.clientSecret;
|
|
403
|
-
if (c.startsWith("bunker://")) {
|
|
404
|
-
const l = new J(c, i), n = new A(P.Nip46Bunker, l), o = new p(b.SetSigner, n), r = new g.Builder(2048);
|
|
405
|
-
r.finish(o.pack(r)), this.postMessage(r.asUint8Array());
|
|
406
|
-
} else if (c.startsWith("nostrconnect://")) {
|
|
407
|
-
const l = new W(c, i), n = new A(P.Nip46QR, l), o = new p(b.SetSigner, n), r = new g.Builder(2048);
|
|
408
|
-
r.finish(o.pack(r)), this.postMessage(r.asUint8Array());
|
|
409
|
-
} else
|
|
410
|
-
console.error("[NativeBackend] Unknown NIP-46 URL format:", c), this._pendingSession = null, this.dispatch("auth", { pubkey: null, hasSigner: false });
|
|
411
|
-
break;
|
|
412
|
-
}
|
|
413
|
-
}
|
|
414
|
-
}
|
|
415
|
-
signEvent(e, a) {
|
|
416
|
-
this._signCB = a;
|
|
417
|
-
const t = new B(
|
|
418
|
-
e.kind,
|
|
419
|
-
e.created_at,
|
|
420
|
-
this.textEncoder.encode(e.content),
|
|
421
|
-
e.tags.map((o) => new _(o)) || []
|
|
422
|
-
), c = new H(t), i = new p(b.SignEvent, c), l = new g.Builder(2048);
|
|
423
|
-
l.finish(i.pack(l));
|
|
424
|
-
const n = l.asUint8Array();
|
|
425
|
-
this.postMessage(n);
|
|
426
|
-
}
|
|
427
|
-
getPublicKey() {
|
|
428
|
-
const e = new p(b.GetPublicKey, new $()), a = new g.Builder(2048);
|
|
429
|
-
a.finish(e.pack(a));
|
|
430
|
-
const t = a.asUint8Array();
|
|
431
|
-
this.postMessage(t);
|
|
432
|
-
}
|
|
433
|
-
onLogout() {
|
|
434
|
-
}
|
|
435
|
-
cleanup() {
|
|
436
|
-
const e = [];
|
|
437
|
-
for (const [a, t] of this.subscriptions.entries())
|
|
438
|
-
t.refCount <= 0 && !this.PERPETUAL_SUBSCRIPTIONS.includes(a) && e.push(a);
|
|
439
|
-
for (const a of e) {
|
|
440
|
-
const t = new E(this.textEncoder.encode(a)), c = new p(b.Unsubscribe, t), i = new g.Builder(256);
|
|
441
|
-
i.finish(c.pack(i));
|
|
442
|
-
const l = i.asUint8Array();
|
|
443
|
-
this.postMessage(l), this.subscriptions.delete(a);
|
|
444
|
-
}
|
|
445
|
-
}
|
|
446
|
-
/**
|
|
447
|
-
* Explicitly tear down the native engine. Call this when the app is shutting
|
|
448
|
-
* down or the backend is no longer needed.
|
|
449
|
-
*/
|
|
450
|
-
deinit() {
|
|
451
|
-
var _a;
|
|
452
|
-
this.deinitialized = true;
|
|
453
|
-
const e = M();
|
|
454
|
-
this.eventEmitter && this.eventListener && this.eventEmitter.removeListener(this.runtimeBridge.eventName, this.eventListener), ((_a = e.activeListener) == null ? void 0 : _a.listener) === this.eventListener && (e.activeListener = void 0), e.instance === this && (e.instance = void 0), this.eventEmitter = null, this.eventListener = null, this.nativeModule.deinit();
|
|
455
|
-
}
|
|
456
|
-
}
|
|
457
|
-
function he(s = {}) {
|
|
458
|
-
const e = M();
|
|
459
|
-
return e.instance && !e.instance.isDeinitialized() ? e.instance : new re(s);
|
|
460
|
-
}
|
|
461
|
-
export {
|
|
462
|
-
re as N,
|
|
463
|
-
he as g
|
|
464
|
-
};
|
package/dist/native.d.ts
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { NostrManagerConfig } from './types';
|
|
2
|
-
import { NostrManagerLike } from './manager';
|
|
3
|
-
/**
|
|
4
|
-
* Native-only entry point for @candypoets/nipworker.
|
|
5
|
-
*
|
|
6
|
-
* This module exports ONLY the NativeBackend and shared utilities.
|
|
7
|
-
* It contains NO WASM imports, NO worker URLs, and NO web-specific code.
|
|
8
|
-
*
|
|
9
|
-
* Use this entry point in LynxJS / React Native / other native environments
|
|
10
|
-
* to avoid bundling wasm-bindgen glue code that crashes QuickJS.
|
|
11
|
-
*
|
|
12
|
-
* @example
|
|
13
|
-
* import { createNostrManager, setManager } from '@candypoets/nipworker/native';
|
|
14
|
-
* const backend = createNostrManager();
|
|
15
|
-
* setManager(backend);
|
|
16
|
-
*/
|
|
17
|
-
export { NativeBackend, getOrCreateNativeBackend } from './NativeBackend';
|
|
18
|
-
export { getManager, setManager, setGlobalManager, hasLynxNativeModule, hasNativeModule } from './manager';
|
|
19
|
-
export type { NostrManagerLike } from './manager';
|
|
20
|
-
export * from './lib/NostrUtils';
|
|
21
|
-
export * from './types';
|
|
22
|
-
/**
|
|
23
|
-
* Create a NativeBackend instance.
|
|
24
|
-
*
|
|
25
|
-
* In native builds this always returns NativeBackend. If you need web WASM
|
|
26
|
-
* backends, import from `@candypoets/nipworker` instead.
|
|
27
|
-
*/
|
|
28
|
-
export declare function createNostrManager(config?: NostrManagerConfig): NostrManagerLike;
|
|
29
|
-
//# sourceMappingURL=native.d.ts.map
|