Move key stuff to util, add pow util
This commit is contained in:
@@ -1,5 +1,14 @@
|
||||
import {isHashedEvent, SignedEvent, HashedEvent, StampedEvent, WRAP, SEAL} from "@welshman/util"
|
||||
import {prep, hash, decrypt, ISigner} from "./util.js"
|
||||
import {
|
||||
isHashedEvent,
|
||||
SignedEvent,
|
||||
HashedEvent,
|
||||
StampedEvent,
|
||||
WRAP,
|
||||
SEAL,
|
||||
prep,
|
||||
hash,
|
||||
} from "@welshman/util"
|
||||
import {decrypt, ISigner} from "./util.js"
|
||||
import {Nip01Signer} from "./signers/nip01.js"
|
||||
|
||||
export const seen = new Map<string, HashedEvent | Error>()
|
||||
|
||||
@@ -1,16 +1,5 @@
|
||||
import {StampedEvent} from "@welshman/util"
|
||||
import {
|
||||
nip04,
|
||||
nip44,
|
||||
own,
|
||||
hash,
|
||||
sign,
|
||||
getPubkey,
|
||||
ISigner,
|
||||
SignOptions,
|
||||
signWithOptions,
|
||||
makeSecret,
|
||||
} from "../util.js"
|
||||
import {StampedEvent, own, hash, sign, getPubkey, makeSecret} from "@welshman/util"
|
||||
import {nip04, nip44, ISigner, SignOptions, signWithOptions} from "../util.js"
|
||||
|
||||
export class Nip01Signer implements ISigner {
|
||||
#pubkey: string
|
||||
|
||||
@@ -1,14 +1,6 @@
|
||||
import {noop} from "@welshman/lib"
|
||||
import {StampedEvent} from "@welshman/util"
|
||||
import {
|
||||
hash,
|
||||
own,
|
||||
signWithOptions,
|
||||
SignOptions,
|
||||
Sign,
|
||||
ISigner,
|
||||
EncryptionImplementation,
|
||||
} from "../util.js"
|
||||
import {StampedEvent, hash, own} from "@welshman/util"
|
||||
import {signWithOptions, SignOptions, Sign, ISigner, EncryptionImplementation} from "../util.js"
|
||||
|
||||
export type Nip07 = {
|
||||
signEvent: Sign
|
||||
|
||||
@@ -5,17 +5,11 @@ import {
|
||||
TrustedEvent,
|
||||
StampedEvent,
|
||||
NOSTR_CONNECT,
|
||||
} from "@welshman/util"
|
||||
import {publish, request, AdapterContext} from "@welshman/net"
|
||||
import {
|
||||
ISigner,
|
||||
EncryptionImplementation,
|
||||
signWithOptions,
|
||||
SignOptions,
|
||||
decrypt,
|
||||
hash,
|
||||
own,
|
||||
} from "../util.js"
|
||||
} from "@welshman/util"
|
||||
import {publish, request, AdapterContext} from "@welshman/net"
|
||||
import {ISigner, EncryptionImplementation, signWithOptions, SignOptions, decrypt} from "../util.js"
|
||||
import {Nip01Signer} from "./nip01.js"
|
||||
|
||||
export type Nip46Context = {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import {NostrSignerPlugin, AppInfo} from "nostr-signer-capacitor-plugin"
|
||||
import * as nip19 from "nostr-tools/nip19"
|
||||
import {SignedEvent, StampedEvent} from "@welshman/util"
|
||||
import {hash, own, signWithOptions, SignOptions, ISigner} from "../util.js"
|
||||
import {SignedEvent, StampedEvent, hash, own} from "@welshman/util"
|
||||
import {signWithOptions, SignOptions, ISigner} from "../util.js"
|
||||
|
||||
export const getNip55 = async (): Promise<AppInfo[]> => {
|
||||
const {apps} = await NostrSignerPlugin.getInstalledSignerApps()
|
||||
|
||||
@@ -1,52 +1,8 @@
|
||||
import {schnorr} from "@noble/curves/secp256k1"
|
||||
import {bytesToHex, hexToBytes} from "@noble/hashes/utils"
|
||||
import {hexToBytes} from "@noble/hashes/utils"
|
||||
import * as nt04 from "nostr-tools/nip04"
|
||||
import * as nt44 from "nostr-tools/nip44"
|
||||
import {generateSecretKey, getPublicKey, getEventHash} from "nostr-tools/pure"
|
||||
import {Emitter, cached, now} from "@welshman/lib"
|
||||
import {
|
||||
SignedEvent,
|
||||
HashedEvent,
|
||||
EventTemplate,
|
||||
StampedEvent,
|
||||
OwnedEvent,
|
||||
isStampedEvent,
|
||||
isOwnedEvent,
|
||||
isHashedEvent,
|
||||
} from "@welshman/util"
|
||||
|
||||
export const makeSecret = () => bytesToHex(generateSecretKey())
|
||||
|
||||
export const getPubkey = (secret: string) => getPublicKey(hexToBytes(secret))
|
||||
|
||||
export const getHash = (event: OwnedEvent) => getEventHash(event)
|
||||
|
||||
export const getSig = (event: HashedEvent, secret: string) =>
|
||||
bytesToHex(schnorr.sign(event.id, secret))
|
||||
|
||||
export const stamp = (event: EventTemplate, created_at = now()) => ({...event, created_at})
|
||||
|
||||
export const own = (event: StampedEvent, pubkey: string) => ({...event, pubkey})
|
||||
|
||||
export const hash = (event: OwnedEvent) => ({...event, id: getHash(event)})
|
||||
|
||||
export const prep = (event: EventTemplate, pubkey: string, created_at = now()) => {
|
||||
if (!isStampedEvent(event as StampedEvent)) {
|
||||
event = stamp(event, created_at)
|
||||
}
|
||||
|
||||
if (!isOwnedEvent(event as OwnedEvent)) {
|
||||
event = own(event as StampedEvent, pubkey)
|
||||
}
|
||||
|
||||
if (!isHashedEvent(event as HashedEvent)) {
|
||||
event = hash(event as OwnedEvent)
|
||||
}
|
||||
|
||||
return event as HashedEvent
|
||||
}
|
||||
|
||||
export const sign = (event: HashedEvent, secret: string) => ({...event, sig: getSig(event, secret)})
|
||||
import {Emitter, cached} from "@welshman/lib"
|
||||
import {SignedEvent, StampedEvent} from "@welshman/util"
|
||||
|
||||
export const nip04 = {
|
||||
detect: (m: string) => m.includes("?iv="),
|
||||
|
||||
Reference in New Issue
Block a user