NIP-94 file headers (#488)
* feat: NIP-94 file headers * Merge NIP-81 tags * disable embedding nip94 for now * merge error * disable broken test * bugfixes * bug: validation failure
This commit is contained in:
@ -50,6 +50,7 @@ _Progress: 8/34 (23%)._
|
||||
- [ ] NIP-58: Badges
|
||||
- [ ] NIP-65: Relay List Metadata
|
||||
- [ ] NIP-78: Application-specific data
|
||||
- [x] NIP-94: File Header
|
||||
|
||||
### Not Applicable
|
||||
|
||||
|
@ -11,6 +11,7 @@ enum EventKind {
|
||||
BadgeAward = 8, // NIP-58
|
||||
SnortSubscriptions = 1000, // NIP-XX
|
||||
Polls = 6969, // NIP-69
|
||||
FileHeader = 1063, // NIP-94
|
||||
Relays = 10002, // NIP-65
|
||||
Ephemeral = 20_000,
|
||||
Auth = 22242, // NIP-42
|
||||
|
@ -27,7 +27,7 @@ export interface TLVEntry {
|
||||
value: string | HexKey | number;
|
||||
}
|
||||
|
||||
export function encodeTLV(hex: string, prefix: NostrPrefix, relays?: string[]) {
|
||||
export function encodeTLV(hex: string, prefix: NostrPrefix, relays?: string[], kind?: number) {
|
||||
if (typeof hex !== "string" || hex.length === 0 || hex.length % 2 !== 0) {
|
||||
return "";
|
||||
}
|
||||
@ -43,8 +43,9 @@ export function encodeTLV(hex: string, prefix: NostrPrefix, relays?: string[]) {
|
||||
return [1, data.length, ...data];
|
||||
})
|
||||
.flat() ?? [];
|
||||
const tl3 = kind ? [3, 4, ...new Uint8Array(new Uint32Array([kind]).buffer).reverse()] : []
|
||||
|
||||
return bech32.encode(prefix, bech32.toWords([...tl0, ...tl1]), 1_000);
|
||||
return bech32.encode(prefix, bech32.toWords([...tl0, ...tl1, ...tl3]), 1_000);
|
||||
}
|
||||
|
||||
export function decodeTLV(str: string) {
|
||||
@ -74,7 +75,7 @@ function decodeTLVEntry(type: TLVEntryType, data: Uint8Array) {
|
||||
return secp.utils.bytesToHex(data);
|
||||
}
|
||||
case TLVEntryType.Kind: {
|
||||
return 0
|
||||
return new Uint32Array(new Uint8Array(data.reverse()).buffer)[0];
|
||||
}
|
||||
case TLVEntryType.Relay: {
|
||||
return new TextDecoder("ASCII").decode(data);
|
||||
|
Reference in New Issue
Block a user