@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,197 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Filter - Nostr subscription filter (NIP-01).
|
|
3
|
+
* Provides a builder pattern for constructing filters.
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Filter class for Nostr subscription queries.
|
|
7
|
+
* Use the builder pattern to construct filters.
|
|
8
|
+
*/
|
|
9
|
+
export class Filter {
|
|
10
|
+
ids;
|
|
11
|
+
authors;
|
|
12
|
+
kinds;
|
|
13
|
+
'#e';
|
|
14
|
+
'#p';
|
|
15
|
+
'#t';
|
|
16
|
+
'#d';
|
|
17
|
+
since;
|
|
18
|
+
until;
|
|
19
|
+
limit;
|
|
20
|
+
/**
|
|
21
|
+
* Create a Filter instance.
|
|
22
|
+
* @param data Optional filter data
|
|
23
|
+
*/
|
|
24
|
+
constructor(data) {
|
|
25
|
+
if (data) {
|
|
26
|
+
if (data.ids)
|
|
27
|
+
this.ids = [...data.ids];
|
|
28
|
+
if (data.authors)
|
|
29
|
+
this.authors = [...data.authors];
|
|
30
|
+
if (data.kinds)
|
|
31
|
+
this.kinds = [...data.kinds];
|
|
32
|
+
if (data['#e'])
|
|
33
|
+
this['#e'] = [...data['#e']];
|
|
34
|
+
if (data['#p'])
|
|
35
|
+
this['#p'] = [...data['#p']];
|
|
36
|
+
if (data['#t'])
|
|
37
|
+
this['#t'] = [...data['#t']];
|
|
38
|
+
if (data['#d'])
|
|
39
|
+
this['#d'] = [...data['#d']];
|
|
40
|
+
if (data.since !== undefined)
|
|
41
|
+
this.since = data.since;
|
|
42
|
+
if (data.until !== undefined)
|
|
43
|
+
this.until = data.until;
|
|
44
|
+
if (data.limit !== undefined)
|
|
45
|
+
this.limit = data.limit;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Create a new Filter builder.
|
|
50
|
+
* @returns Filter builder instance
|
|
51
|
+
*/
|
|
52
|
+
static builder() {
|
|
53
|
+
return new FilterBuilder();
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Convert the filter to a plain object for JSON serialization.
|
|
57
|
+
* Only includes defined properties.
|
|
58
|
+
* @returns Plain object representation
|
|
59
|
+
*/
|
|
60
|
+
toJSON() {
|
|
61
|
+
const result = {};
|
|
62
|
+
if (this.ids && this.ids.length > 0)
|
|
63
|
+
result.ids = this.ids;
|
|
64
|
+
if (this.authors && this.authors.length > 0)
|
|
65
|
+
result.authors = this.authors;
|
|
66
|
+
if (this.kinds && this.kinds.length > 0)
|
|
67
|
+
result.kinds = this.kinds;
|
|
68
|
+
if (this['#e'] && this['#e'].length > 0)
|
|
69
|
+
result['#e'] = this['#e'];
|
|
70
|
+
if (this['#p'] && this['#p'].length > 0)
|
|
71
|
+
result['#p'] = this['#p'];
|
|
72
|
+
if (this['#t'] && this['#t'].length > 0)
|
|
73
|
+
result['#t'] = this['#t'];
|
|
74
|
+
if (this['#d'] && this['#d'].length > 0)
|
|
75
|
+
result['#d'] = this['#d'];
|
|
76
|
+
if (this.since !== undefined)
|
|
77
|
+
result.since = this.since;
|
|
78
|
+
if (this.until !== undefined)
|
|
79
|
+
result.until = this.until;
|
|
80
|
+
if (this.limit !== undefined)
|
|
81
|
+
result.limit = this.limit;
|
|
82
|
+
return result;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Parse a filter from JSON data.
|
|
86
|
+
* @param json JSON object or string
|
|
87
|
+
* @returns Filter instance
|
|
88
|
+
*/
|
|
89
|
+
static fromJSON(json) {
|
|
90
|
+
const data = typeof json === 'string' ? JSON.parse(json) : json;
|
|
91
|
+
return new Filter(data);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Builder class for constructing Filter instances.
|
|
96
|
+
*/
|
|
97
|
+
export class FilterBuilder {
|
|
98
|
+
data = {};
|
|
99
|
+
ids(idsOrFirst, ...rest) {
|
|
100
|
+
if (Array.isArray(idsOrFirst)) {
|
|
101
|
+
this.data.ids = [...idsOrFirst];
|
|
102
|
+
}
|
|
103
|
+
else {
|
|
104
|
+
this.data.ids = [idsOrFirst, ...rest];
|
|
105
|
+
}
|
|
106
|
+
return this;
|
|
107
|
+
}
|
|
108
|
+
authors(authorsOrFirst, ...rest) {
|
|
109
|
+
if (Array.isArray(authorsOrFirst)) {
|
|
110
|
+
this.data.authors = [...authorsOrFirst];
|
|
111
|
+
}
|
|
112
|
+
else {
|
|
113
|
+
this.data.authors = [authorsOrFirst, ...rest];
|
|
114
|
+
}
|
|
115
|
+
return this;
|
|
116
|
+
}
|
|
117
|
+
kinds(kindsOrFirst, ...rest) {
|
|
118
|
+
if (Array.isArray(kindsOrFirst)) {
|
|
119
|
+
this.data.kinds = [...kindsOrFirst];
|
|
120
|
+
}
|
|
121
|
+
else {
|
|
122
|
+
this.data.kinds = [kindsOrFirst, ...rest];
|
|
123
|
+
}
|
|
124
|
+
return this;
|
|
125
|
+
}
|
|
126
|
+
eTags(eTagsOrFirst, ...rest) {
|
|
127
|
+
if (Array.isArray(eTagsOrFirst)) {
|
|
128
|
+
this.data['#e'] = [...eTagsOrFirst];
|
|
129
|
+
}
|
|
130
|
+
else {
|
|
131
|
+
this.data['#e'] = [eTagsOrFirst, ...rest];
|
|
132
|
+
}
|
|
133
|
+
return this;
|
|
134
|
+
}
|
|
135
|
+
pTags(pTagsOrFirst, ...rest) {
|
|
136
|
+
if (Array.isArray(pTagsOrFirst)) {
|
|
137
|
+
this.data['#p'] = [...pTagsOrFirst];
|
|
138
|
+
}
|
|
139
|
+
else {
|
|
140
|
+
this.data['#p'] = [pTagsOrFirst, ...rest];
|
|
141
|
+
}
|
|
142
|
+
return this;
|
|
143
|
+
}
|
|
144
|
+
tTags(tTagsOrFirst, ...rest) {
|
|
145
|
+
if (Array.isArray(tTagsOrFirst)) {
|
|
146
|
+
this.data['#t'] = [...tTagsOrFirst];
|
|
147
|
+
}
|
|
148
|
+
else {
|
|
149
|
+
this.data['#t'] = [tTagsOrFirst, ...rest];
|
|
150
|
+
}
|
|
151
|
+
return this;
|
|
152
|
+
}
|
|
153
|
+
dTags(dTagsOrFirst, ...rest) {
|
|
154
|
+
if (Array.isArray(dTagsOrFirst)) {
|
|
155
|
+
this.data['#d'] = [...dTagsOrFirst];
|
|
156
|
+
}
|
|
157
|
+
else {
|
|
158
|
+
this.data['#d'] = [dTagsOrFirst, ...rest];
|
|
159
|
+
}
|
|
160
|
+
return this;
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* Set minimum timestamp (inclusive).
|
|
164
|
+
* @param since Unix timestamp in seconds
|
|
165
|
+
* @returns This builder for chaining
|
|
166
|
+
*/
|
|
167
|
+
since(since) {
|
|
168
|
+
this.data.since = since;
|
|
169
|
+
return this;
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* Set maximum timestamp (inclusive).
|
|
173
|
+
* @param until Unix timestamp in seconds
|
|
174
|
+
* @returns This builder for chaining
|
|
175
|
+
*/
|
|
176
|
+
until(until) {
|
|
177
|
+
this.data.until = until;
|
|
178
|
+
return this;
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* Set maximum number of events to return.
|
|
182
|
+
* @param limit Maximum number of events
|
|
183
|
+
* @returns This builder for chaining
|
|
184
|
+
*/
|
|
185
|
+
limit(limit) {
|
|
186
|
+
this.data.limit = limit;
|
|
187
|
+
return this;
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
* Build the Filter instance.
|
|
191
|
+
* @returns Filter instance
|
|
192
|
+
*/
|
|
193
|
+
build() {
|
|
194
|
+
return new Filter(this.data);
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
//# sourceMapp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/B,CAAC;CACF"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Protocol module - Nostr protocol types and classes
|
|
3
|
+
*/
|
|
4
|
+
export { Event } from './Event.js';
|
|
5
|
+
export { Filter, FilterBuilder } from './Filter.js';
|
|
6
|
+
export * as EventKinds from './EventKinds.js';
|
|
7
|
+
export * from './EventKinds.js';
|
|
8
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/protocol/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAEnC,OAAO,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAEpD,OAAO,KAAK,UAAU,MAAM,iBAAiB,CAAC;AAC9C,cAAc,iBAAiB,CAAC"}
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TokenTransferProtocol - Encapsulate Unicity token transfers over Nostr.
|
|
3
|
+
* Uses NIP-04 encryption with optional GZIP compression.
|
|
4
|
+
*/
|
|
5
|
+
import { Event } from '../protocol/Event.js';
|
|
6
|
+
import * as EventKinds from '../protocol/EventKinds.js';
|
|
7
|
+
/** Prefix for token transfer messages */
|
|
8
|
+
const MESSAGE_PREFIX = 'token_transfer:';
|
|
9
|
+
/**
|
|
10
|
+
* Create a token transfer event.
|
|
11
|
+
*
|
|
12
|
+
* Event structure:
|
|
13
|
+
* - Kind: 31113 (TOKEN_TRANSFER - Unicity custom)
|
|
14
|
+
* - Tags:
|
|
15
|
+
* - ["p", "<recipient_pubkey_hex>"] - Recipient
|
|
16
|
+
* - ["type", "token_transfer"] - Event type
|
|
17
|
+
* - ["amount", "<amount>"] - Optional amount
|
|
18
|
+
* - ["symbol", "<symbol>"] - Optional token symbol
|
|
19
|
+
* - Content: NIP-04 encrypted "token_transfer:{tokenJson}"
|
|
20
|
+
*
|
|
21
|
+
* @param keyManager Key manager with signing keys
|
|
22
|
+
* @param recipientPubkeyHex Recipient's public key (hex)
|
|
23
|
+
* @param tokenJson Token JSON string
|
|
24
|
+
* @param amount Optional amount for metadata
|
|
25
|
+
* @param symbol Optional token symbol for metadata
|
|
26
|
+
* @returns Signed event
|
|
27
|
+
*/
|
|
28
|
+
export async function createTokenTransferEvent(keyManager, recipientPubkeyHex, tokenJson, amount, symbol) {
|
|
29
|
+
// Encrypt the token data
|
|
30
|
+
const message = MESSAGE_PREFIX + tokenJson;
|
|
31
|
+
const encryptedContent = await keyManager.encryptHex(message, recipientPubkeyHex);
|
|
32
|
+
// Build tags
|
|
33
|
+
const tags = [
|
|
34
|
+
['p', recipientPubkeyHex],
|
|
35
|
+
['type', 'token_transfer'],
|
|
36
|
+
];
|
|
37
|
+
if (amount !== undefined) {
|
|
38
|
+
tags.push(['amount', String(amount)]);
|
|
39
|
+
}
|
|
40
|
+
if (symbol !== undefined) {
|
|
41
|
+
tags.push(['symbol', symbol]);
|
|
42
|
+
}
|
|
43
|
+
const event = Event.create(keyManager, {
|
|
44
|
+
kind: EventKinds.TOKEN_TRANSFER,
|
|
45
|
+
tags,
|
|
46
|
+
content: encryptedContent,
|
|
47
|
+
});
|
|
48
|
+
return event;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Parse a token transfer event.
|
|
52
|
+
* Decrypts and decompresses the token data.
|
|
53
|
+
*
|
|
54
|
+
* @param event Token transfer event
|
|
55
|
+
* @param keyManager Key manager for decryption
|
|
56
|
+
* @returns Token JSON string
|
|
57
|
+
* @throws Error if the event is not a valid token transfer
|
|
58
|
+
*/
|
|
59
|
+
export async function parseTokenTransfer(event, keyManager) {
|
|
60
|
+
// Verify event kind
|
|
61
|
+
if (event.kind !== EventKinds.TOKEN_TRANSFER) {
|
|
62
|
+
throw new Error('Event is not a token transfer');
|
|
63
|
+
}
|
|
64
|
+
// Verify event type tag
|
|
65
|
+
const eventType = event.getTagValue('type');
|
|
66
|
+
if (eventType !== 'token_transfer') {
|
|
67
|
+
throw new Error('Event type is not token_transfer');
|
|
68
|
+
}
|
|
69
|
+
// Determine the sender's public key
|
|
70
|
+
let senderPubkeyHex;
|
|
71
|
+
if (keyManager.isMyPublicKey(event.pubkey)) {
|
|
72
|
+
// We sent this event, decrypt with recipient's key
|
|
73
|
+
const recipientPubkey = event.getTagValue('p');
|
|
74
|
+
if (!recipientPubkey) {
|
|
75
|
+
throw new Error('No recipient found in event');
|
|
76
|
+
}
|
|
77
|
+
senderPubkeyHex = recipientPubkey;
|
|
78
|
+
}
|
|
79
|
+
else {
|
|
80
|
+
// We received this event, decrypt with sender's key
|
|
81
|
+
senderPubkeyHex = event.pubkey;
|
|
82
|
+
}
|
|
83
|
+
// Decrypt the content
|
|
84
|
+
let decrypted;
|
|
85
|
+
try {
|
|
86
|
+
decrypted = await keyManager.decryptHex(event.content, senderPubkeyHex);
|
|
87
|
+
}
|
|
88
|
+
catch (error) {
|
|
89
|
+
// Fallback: try hex decoding for backward compatibility
|
|
90
|
+
try {
|
|
91
|
+
const { hexToBytes } = await import('@noble/hashes/utils');
|
|
92
|
+
decrypted = new TextDecoder().decode(hexToBytes(event.content));
|
|
93
|
+
}
|
|
94
|
+
catch {
|
|
95
|
+
throw error; // Re-throw original error
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
// Strip the message prefix
|
|
99
|
+
if (!decrypted.startsWith(MESSAGE_PREFIX)) {
|
|
100
|
+
throw new Error('Invalid token transfer format');
|
|
101
|
+
}
|
|
102
|
+
return decrypted.slice(MESSAGE_PREFIX.length);
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Get the amount from a token transfer event.
|
|
106
|
+
* @param event Token transfer event
|
|
107
|
+
* @returns Amount, or undefined if not specified
|
|
108
|
+
*/
|
|
109
|
+
export function getAmount(event) {
|
|
110
|
+
const amount = event.getTagValue('amount');
|
|
111
|
+
if (amount === undefined) {
|
|
112
|
+
return undefined;
|
|
113
|
+
}
|
|
114
|
+
try {
|
|
115
|
+
return BigInt(amount);
|
|
116
|
+
}
|
|
117
|
+
catch {
|
|
118
|
+
return undefined;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Get the symbol from a token transfer event.
|
|
123
|
+
* @param event Token transfer event
|
|
124
|
+
* @returns Symbol, or undefined if not specified
|
|
125
|
+
*/
|
|
126
|
+
export function getSymbol(event) {
|
|
127
|
+
return event.getTagValue('symbol');
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Check if an event is a token transfer.
|
|
131
|
+
* @param event Event to check
|
|
132
|
+
* @returns true if the event is a token transfer
|
|
133
|
+
*/
|
|
134
|
+
export function isTokenTransfer(event) {
|
|
135
|
+
return (event.kind === EventKinds.TOKEN_TRANSFER &&
|
|
136
|
+
event.getTagValue('type') === 'token_transfer');
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Get the recipient public key from a token transfer event.
|
|
140
|
+
* @param event Token transfer event
|
|
141
|
+
* @returns Recipient public key (hex), or undefined if not found
|
|
142
|
+
*/
|
|
143
|
+
export function getRecipient(event) {
|
|
144
|
+
return event.getTagValue('p');
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* Get the sender public key from a token transfer event.
|
|
148
|
+
* @param event Token transfer event
|
|
149
|
+
* @returns Sender public key (hex)
|
|
150
|
+
*/
|
|
151
|
+
export function getSender(event) {
|
|
152
|
+
return event.pubkey;
|
|
153
|
+
}
|
|
154
|
+
//# sourceMappingURL=TokenTransferProtocol.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TokenTransferProtocol.js","sourceRoot":"","sources":["../../../src/token/TokenTransferProtocol.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAAE,KAAK,EAAE,MAAM,sBAAsB,CAAC;AAC7C,OAAO,KAAK,UAAU,MAAM,2BAA2B,CAAC;AAExD,yCAAyC;AACz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IG;AACH,MAAM,UAAU,SAAS,CAAC,KAAY;IACpC,MAAM,MAAM,GAAG,KAAK,CAAC,WAAW,CAAC,QAAQ,CAAC,CAAC;IAC3C,IAAI,MAAM,KAAK,SAAS,EAAE,CAAC;QACzB,OAAO,SAAS,CAAC;IACnB,CAAC;IACD,IAAI,CAAC;QACH,OAAO,MAAM,CAAC,MAAM,CAAC,CAAC;IACxB,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,SAAS,CAAC;IACnB,CAAC;AACH,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,SAAS,CAAC,KAAY;IACpC,OAAO,KAAK,CAAC,WAAW,CAAC,QAAQ,CAAC,CAAC;AACrC,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,eAAe,CAAC,KAAY;IAC1C,OAAO,CACL,KAAK,CAAC,IAAI,KAAK,UAAU,CAAC,cAAc;QACxC,KAAK,CAAC,WAAW,CAAC,MAAM,CAAC,KAAK,gBAAgB,CAC/C,CAAC;AACJ,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,YAAY,CAAC,KAAY;IACvC,OAAO,KAAK,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC;AAChC,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,SAAS,CAAC,KAAY;IACpC,OAAO,KAAK,CAAC,MAAM,CAAC;AACtB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/token/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,qBAAqB,MAAM,4BAA4B,CAAC;AACpE,cAAc,4BAA4B,CAAC"}
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* NostrKeyManager - High-level cryptographic operations manager for Nostr.
|
|
3
|
+
* Manages key pairs, signing, and NIP-04 encryption/decryption.
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* NostrKeyManager provides a high-level interface for cryptographic operations.
|
|
7
|
+
* It manages a Nostr key pair and provides methods for signing, verification,
|
|
8
|
+
* and NIP-04 encryption/decryption.
|
|
9
|
+
*/
|
|
10
|
+
export declare class NostrKeyManager {
|
|
11
|
+
private privateKey;
|
|
12
|
+
private publicKey;
|
|
13
|
+
private cleared;
|
|
14
|
+
/**
|
|
15
|
+
* Private constructor - use static factory methods instead.
|
|
16
|
+
*/
|
|
17
|
+
private constructor();
|
|
18
|
+
/**
|
|
19
|
+
* Create a NostrKeyManager from a 32-byte private key.
|
|
20
|
+
* @param privateKey 32-byte private key
|
|
21
|
+
* @returns NostrKeyManager instance
|
|
22
|
+
*/
|
|
23
|
+
static fromPrivateKey(privateKey: Uint8Array): NostrKeyManager;
|
|
24
|
+
/**
|
|
25
|
+
* Create a NostrKeyManager from a hex-encoded private key.
|
|
26
|
+
* @param privateKeyHex Hex-encoded private key (64 characters)
|
|
27
|
+
* @returns NostrKeyManager instance
|
|
28
|
+
*/
|
|
29
|
+
static fromPrivateKeyHex(privateKeyHex: string): NostrKeyManager;
|
|
30
|
+
/**
|
|
31
|
+
* Create a NostrKeyManager from a Bech32-encoded nsec string.
|
|
32
|
+
* @param nsec nsec-encoded private key
|
|
33
|
+
* @returns NostrKeyManager instance
|
|
34
|
+
*/
|
|
35
|
+
static fromNsec(nsec: string): NostrKeyManager;
|
|
36
|
+
/**
|
|
37
|
+
* Generate a new random key pair.
|
|
38
|
+
* @returns NostrKeyManager instance with a new random key pair
|
|
39
|
+
*/
|
|
40
|
+
static generate(): NostrKeyManager;
|
|
41
|
+
/**
|
|
42
|
+
* Check if the key manager has been cleared.
|
|
43
|
+
* @throws Error if the key manager has been cleared
|
|
44
|
+
*/
|
|
45
|
+
private ensureNotCleared;
|
|
46
|
+
/**
|
|
47
|
+
* Get a copy of the private key bytes.
|
|
48
|
+
* @returns 32-byte private key (copy)
|
|
49
|
+
*/
|
|
50
|
+
getPrivateKey(): Uint8Array;
|
|
51
|
+
/**
|
|
52
|
+
* Get the hex-encoded private key.
|
|
53
|
+
* @returns Hex-encoded private key (64 characters)
|
|
54
|
+
*/
|
|
55
|
+
getPrivateKeyHex(): string;
|
|
56
|
+
/**
|
|
57
|
+
* Get the Bech32-encoded nsec private key.
|
|
58
|
+
* @returns nsec-encoded private key
|
|
59
|
+
*/
|
|
60
|
+
getNsec(): string;
|
|
61
|
+
/**
|
|
62
|
+
* Get a copy of the x-only public key bytes.
|
|
63
|
+
* @returns 32-byte x-only public key (copy)
|
|
64
|
+
*/
|
|
65
|
+
getPublicKey(): Uint8Array;
|
|
66
|
+
/**
|
|
67
|
+
* Get the hex-encoded public key.
|
|
68
|
+
* @returns Hex-encoded public key (64 characters)
|
|
69
|
+
*/
|
|
70
|
+
getPublicKeyHex(): string;
|
|
71
|
+
/**
|
|
72
|
+
* Get the Bech32-encoded npub public key.
|
|
73
|
+
* @returns npub-encoded public key
|
|
74
|
+
*/
|
|
75
|
+
getNpub(): string;
|
|
76
|
+
/**
|
|
77
|
+
* Sign a 32-byte message hash using BIP-340 Schnorr signature.
|
|
78
|
+
* @param messageHash 32-byte message hash
|
|
79
|
+
* @returns 64-byte Schnorr signature
|
|
80
|
+
*/
|
|
81
|
+
sign(messageHash: Uint8Array): Uint8Array;
|
|
82
|
+
/**
|
|
83
|
+
* Sign a message hash and return hex-encoded signature.
|
|
84
|
+
* @param messageHash 32-byte message hash
|
|
85
|
+
* @returns Hex-encoded 64-byte Schnorr signature
|
|
86
|
+
*/
|
|
87
|
+
signHex(messageHash: Uint8Array): string;
|
|
88
|
+
/**
|
|
89
|
+
* Verify a Schnorr signature (static method).
|
|
90
|
+
* @param signature 64-byte Schnorr signature
|
|
91
|
+
* @param messageHash 32-byte message hash
|
|
92
|
+
* @param publicKey 32-byte x-only public key
|
|
93
|
+
* @returns true if the signature is valid
|
|
94
|
+
*/
|
|
95
|
+
static verify(signature: Uint8Array, messageHash: Uint8Array, publicKey: Uint8Array): boolean;
|
|
96
|
+
/**
|
|
97
|
+
* Verify a hex-encoded Schnorr signature (static method).
|
|
98
|
+
* @param signatureHex Hex-encoded 64-byte signature
|
|
99
|
+
* @param messageHash 32-byte message hash
|
|
100
|
+
* @param publicKeyHex Hex-encoded 32-byte public key
|
|
101
|
+
* @returns true if the signature is valid
|
|
102
|
+
*/
|
|
103
|
+
static verifyHex(signatureHex: string, messageHash: Uint8Array, publicKeyHex: string): boolean;
|
|
104
|
+
/**
|
|
105
|
+
* Encrypt a message using NIP-04 encryption.
|
|
106
|
+
* @param message Message to encrypt
|
|
107
|
+
* @param recipientPublicKey 32-byte x-only public key of recipient
|
|
108
|
+
* @returns Encrypted content string
|
|
109
|
+
*/
|
|
110
|
+
encrypt(message: string, recipientPublicKey: Uint8Array): Promise<string>;
|
|
111
|
+
/**
|
|
112
|
+
* Encrypt a message using hex-encoded recipient public key.
|
|
113
|
+
* @param message Message to encrypt
|
|
114
|
+
* @param recipientPublicKeyHex Hex-encoded recipient public key
|
|
115
|
+
* @returns Encrypted content string
|
|
116
|
+
*/
|
|
117
|
+
encryptHex(message: string, recipientPublicKeyHex: string): Promise<string>;
|
|
118
|
+
/**
|
|
119
|
+
* Decrypt a NIP-04 encrypted message.
|
|
120
|
+
* @param encryptedContent Encrypted content string
|
|
121
|
+
* @param senderPublicKey 32-byte x-only public key of sender
|
|
122
|
+
* @returns Decrypted message
|
|
123
|
+
*/
|
|
124
|
+
decrypt(encryptedContent: string, senderPublicKey: Uint8Array): Promise<string>;
|
|
125
|
+
/**
|
|
126
|
+
* Decrypt a message using hex-encoded sender public key.
|
|
127
|
+
* @param encryptedContent Encrypted content string
|
|
128
|
+
* @param senderPublicKeyHex Hex-encoded sender public key
|
|
129
|
+
* @returns Decrypted message
|
|
130
|
+
*/
|
|
131
|
+
decryptHex(encryptedContent: string, senderPublicKeyHex: string): Promise<string>;
|
|
132
|
+
/**
|
|
133
|
+
* Derive a shared secret using ECDH.
|
|
134
|
+
* @param theirPublicKey 32-byte x-only public key
|
|
135
|
+
* @returns 32-byte shared secret
|
|
136
|
+
*/
|
|
137
|
+
deriveSharedSecret(theirPublicKey: Uint8Array): Uint8Array;
|
|
138
|
+
/**
|
|
139
|
+
* Check if a public key matches this key manager's public key.
|
|
140
|
+
* @param publicKeyHex Hex-encoded public key to check
|
|
141
|
+
* @returns true if the public key matches
|
|
142
|
+
*/
|
|
143
|
+
isMyPublicKey(publicKeyHex: string): boolean;
|
|
144
|
+
/**
|
|
145
|
+
* Clear the private key from memory.
|
|
146
|
+
* After calling this method, the key manager cannot be used for signing or decryption.
|
|
147
|
+
*/
|
|
148
|
+
clear(): void;
|
|
149
|
+
}
|
|
150
|
+
//# sourceMappingURL=NostrKeyManager.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"NostrKeyManager.d.ts","sourceRoot":"","sources":["../../src/NostrKeyManager.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAOH;;;;GAIG;AACH,qBAAa,eAAe;IAC1B,OAAO,CAAC,UAAU,CAAa;IAC/B,OAAO,CAAC,SAAS,CAAa;IAC9B,OAAO,CAAC,OAAO,CAAkB;IAEjC;;OAEG;IACH,OAAO;IASP;;;;OAIG;IACH,MAAM,CAAC,cAAc,CAAC,UAAU,EAAE,UAAU,GAAG,eAAe;IAI9D;;;;OAIG;IACH,MAAM,CAAC,iBAAiB,CAAC,aAAa,EAAE,MAAM,GAAG,eAAe;IAKhE;;;;OAIG;IACH,MAAM,CAAC,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,eAAe;IAK9C;;;OAGG;IACH,MAAM,CAAC,QAAQ,IAAI,eAAe;IAKlC;;;OAGG;IACH,OAAO,CAAC,gBAAgB;IAMxB;;;OAGG;IACH,aAAa,IAAI,UAAU;IAK3B;;;OAGG;IACH,gBAAgB,IAAI,MAAM;IAK1B;;;OAGG;IACH,OAAO,IAAI,MAAM;IAKjB;;;OAGG;IACH,YAAY,IAAI,UAAU;IAK1B;;;OAGG;IACH,eAAe,IAAI,MAAM;IAKzB;;;OAGG;IACH,O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