mirror of
https://github.com/coracle-social/coracle.git
synced 2024-09-29 08:21:20 +00:00
Add support for nip44 on extensions
This commit is contained in:
parent
bb91d52b0d
commit
c30791d8b7
@ -1,5 +1,11 @@
|
|||||||
# Changelog
|
# Changelog
|
||||||
|
|
||||||
|
# 0.4.3
|
||||||
|
|
||||||
|
- [x] Add follow all to onboarding topics
|
||||||
|
- [x] Add FORCE_RELAYS environment variable
|
||||||
|
- [x] Add support for extensions that implement nip44
|
||||||
|
|
||||||
# 0.4.2
|
# 0.4.2
|
||||||
|
|
||||||
- [x] Require signer on some routes
|
- [x] Require signer on some routes
|
||||||
|
@ -6,8 +6,8 @@ import {withExtension} from "./nip07"
|
|||||||
|
|
||||||
export class Nip04 {
|
export class Nip04 {
|
||||||
constructor(
|
constructor(
|
||||||
readonly session: Session | null,
|
readonly session: Session,
|
||||||
readonly connect: Connect | null,
|
readonly connect: Connect,
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
isEnabled() {
|
isEnabled() {
|
||||||
|
@ -4,6 +4,7 @@ import {cached} from "paravel"
|
|||||||
import {switcherFn} from "hurdak"
|
import {switcherFn} from "hurdak"
|
||||||
import type {Session} from "src/engine/session/model"
|
import type {Session} from "src/engine/session/model"
|
||||||
import type {Connect} from "./connect"
|
import type {Connect} from "./connect"
|
||||||
|
import {withExtension} from "./nip07"
|
||||||
|
|
||||||
// Deriving shared secret is an expensive computation, cache it
|
// Deriving shared secret is an expensive computation, cache it
|
||||||
export const getSharedSecret = cached({
|
export const getSharedSecret = cached({
|
||||||
@ -19,7 +20,15 @@ export class Nip44 {
|
|||||||
) {}
|
) {}
|
||||||
|
|
||||||
isEnabled() {
|
isEnabled() {
|
||||||
return ["privkey", "connect"].includes(this.session?.method)
|
if (["privkey", "connect"].includes(this.session?.method)) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.session?.method === "extension") {
|
||||||
|
return Boolean((window as any).nostr?.nip44)
|
||||||
|
}
|
||||||
|
|
||||||
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
encrypt(message: string, pk: string, sk: string) {
|
encrypt(message: string, pk: string, sk: string) {
|
||||||
@ -35,6 +44,7 @@ export class Nip44 {
|
|||||||
|
|
||||||
return switcherFn(method, {
|
return switcherFn(method, {
|
||||||
privkey: () => this.encrypt(message, pk, privkey),
|
privkey: () => this.encrypt(message, pk, privkey),
|
||||||
|
extension: () => withExtension(ext => ext.nip44.encrypt(pk, message)),
|
||||||
connect: () => this.connect.broker.nip44Encrypt(pk, message),
|
connect: () => this.connect.broker.nip44Encrypt(pk, message),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -44,6 +54,7 @@ export class Nip44 {
|
|||||||
|
|
||||||
return switcherFn(method, {
|
return switcherFn(method, {
|
||||||
privkey: () => this.decrypt(message, pk, privkey),
|
privkey: () => this.decrypt(message, pk, privkey),
|
||||||
|
extension: () => withExtension(ext => ext.nip44.decrypt(pk, message)),
|
||||||
connect: () => this.connect.broker.nip44Decrypt(pk, message),
|
connect: () => this.connect.broker.nip44Decrypt(pk, message),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user