mirror of
https://github.com/nbd-wtf/nostr-tools.git
synced 2025-12-09 16:48:50 +00:00
Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
63ccc8b4c8 | ||
|
|
7cf7df88db | ||
|
|
bded539122 | ||
|
|
3647bbd68a |
19
nip46.ts
19
nip46.ts
@@ -118,7 +118,7 @@ export class BunkerSigner {
|
|||||||
const { id, result, error } = JSON.parse(await decrypt(clientSecretKey, event.pubkey, event.content))
|
const { id, result, error } = JSON.parse(await decrypt(clientSecretKey, event.pubkey, event.content))
|
||||||
|
|
||||||
if (result === 'auth_url' && waitingForAuth[id]) {
|
if (result === 'auth_url' && waitingForAuth[id]) {
|
||||||
delete listeners[id]
|
delete waitingForAuth[id]
|
||||||
|
|
||||||
if (params.onauth) {
|
if (params.onauth) {
|
||||||
params.onauth(error)
|
params.onauth(error)
|
||||||
@@ -279,22 +279,35 @@ export async function createAccount(
|
|||||||
return rpc
|
return rpc
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// @deprecated use fetchBunkerProviders instead
|
||||||
|
export const fetchCustodialBunkers = fetchBunkerProviders
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fetches info on available providers that announce themselves using NIP-89 events.
|
* Fetches info on available providers that announce themselves using NIP-89 events.
|
||||||
* @returns A promise that resolves to an array of available bunker objects.
|
* @returns A promise that resolves to an array of available bunker objects.
|
||||||
*/
|
*/
|
||||||
export async function fetchCustodialBunkers(pool: AbstractSimplePool, relays: string[]): Promise<BunkerProfile[]> {
|
export async function fetchBunkerProviders(pool: AbstractSimplePool, relays: string[]): Promise<BunkerProfile[]> {
|
||||||
const events = await pool.querySync(relays, {
|
const events = await pool.querySync(relays, {
|
||||||
kinds: [Handlerinformation],
|
kinds: [Handlerinformation],
|
||||||
'#k': [NostrConnect.toString()],
|
'#k': [NostrConnect.toString()],
|
||||||
})
|
})
|
||||||
|
|
||||||
|
events.sort((a, b) => b.created_at - a.created_at)
|
||||||
|
|
||||||
// validate bunkers by checking their NIP-05 and pubkey
|
// validate bunkers by checking their NIP-05 and pubkey
|
||||||
// map to a more useful object
|
// map to a more useful object
|
||||||
const validatedBunkers = await Promise.all(
|
const validatedBunkers = await Promise.all(
|
||||||
events.map(async event => {
|
events.map(async (event, i) => {
|
||||||
try {
|
try {
|
||||||
const content = JSON.parse(event.content)
|
const content = JSON.parse(event.content)
|
||||||
|
|
||||||
|
// skip duplicates
|
||||||
|
try {
|
||||||
|
if (events.findIndex(ev => JSON.parse(ev.content).nip05 === content.nip05) !== i) return undefined
|
||||||
|
} catch (err) {
|
||||||
|
/***/
|
||||||
|
}
|
||||||
|
|
||||||
const bp = await queryBunkerProfile(content.nip05)
|
const bp = await queryBunkerProfile(content.nip05)
|
||||||
if (bp && bp.pubkey === event.pubkey && bp.relays.length) {
|
if (bp && bp.pubkey === event.pubkey && bp.relays.length) {
|
||||||
return {
|
return {
|
||||||
|
|||||||
@@ -1,14 +1,9 @@
|
|||||||
import crypto from 'node:crypto'
|
|
||||||
import { describe, test, expect } from 'bun:test'
|
import { describe, test, expect } from 'bun:test'
|
||||||
import { hexToBytes } from '@noble/hashes/utils'
|
import { hexToBytes } from '@noble/hashes/utils'
|
||||||
import { makeNwcRequestEvent, parseConnectionString } from './nip47'
|
import { makeNwcRequestEvent, parseConnectionString } from './nip47'
|
||||||
import { decrypt } from './nip04.ts'
|
import { decrypt } from './nip04.ts'
|
||||||
import { NWCWalletRequest } from './kinds.ts'
|
import { NWCWalletRequest } from './kinds.ts'
|
||||||
|
|
||||||
// @ts-ignore
|
|
||||||
// eslint-disable-next-line no-undef
|
|
||||||
globalThis.crypto = crypto
|
|
||||||
|
|
||||||
describe('parseConnectionString', () => {
|
describe('parseConnectionString', () => {
|
||||||
test('returns pubkey, relay, and secret if connection string is valid', () => {
|
test('returns pubkey, relay, and secret if connection string is valid', () => {
|
||||||
const connectionString =
|
const connectionString =
|
||||||
|
|||||||
14
nip96.ts
14
nip96.ts
@@ -1,5 +1,7 @@
|
|||||||
|
import { sha256 } from '@noble/hashes/sha256'
|
||||||
import { EventTemplate } from './core'
|
import { EventTemplate } from './core'
|
||||||
import { FileServerPreference } from './kinds'
|
import { FileServerPreference } from './kinds'
|
||||||
|
import { bytesToHex } from '@noble/hashes/utils'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents the configuration for a server compliant with NIP-96.
|
* Represents the configuration for a server compliant with NIP-96.
|
||||||
@@ -576,15 +578,5 @@ export function generateFSPEventTemplate(serverUrls: string[]): EventTemplate {
|
|||||||
* @returns A promise that resolves to the SHA-256 hash of the file.
|
* @returns A promise that resolves to the SHA-256 hash of the file.
|
||||||
*/
|
*/
|
||||||
export async function calculateFileHash(file: Blob): Promise<string> {
|
export async function calculateFileHash(file: Blob): Promise<string> {
|
||||||
// Read the file as an ArrayBuffer
|
return bytesToHex(sha256(new Uint8Array(await file.arrayBuffer())))
|
||||||
const buffer = await file.arrayBuffer()
|
|
||||||
|
|
||||||
// Calculate the SHA-256 hash of the file
|
|
||||||
const hashBuffer = await crypto.subtle.digest('SHA-256', buffer)
|
|
||||||
|
|
||||||
// Convert the hash to a hexadecimal string
|
|
||||||
const hashArray = Array.from(new Uint8Array(hashBuffer))
|
|
||||||
const hashHex = hashArray.map(b => b.toString(16).padStart(2, '0')).join('')
|
|
||||||
|
|
||||||
return hashHex
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"name": "nostr-tools",
|
"name": "nostr-tools",
|
||||||
"version": "2.3.0",
|
"version": "2.3.1",
|
||||||
"description": "Tools for making a Nostr client.",
|
"description": "Tools for making a Nostr client.",
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
|
|||||||
Reference in New Issue
Block a user