mirror of
https://github.com/BlowaterNostr/blowater.git
synced 2024-10-18 07:33:22 +00:00
integrate nip44 (#372)
This commit is contained in:
parent
4650aee9d3
commit
0d43a4e597
@ -130,7 +130,7 @@ export class OtherConfig implements PinListGetter, NostrEventAdder {
|
||||
pusher: Channel<NostrEvent>,
|
||||
lamport: LamportTime,
|
||||
) {
|
||||
const decrypted = await ctx.decrypt(ctx.publicKey.hex, event.content);
|
||||
const decrypted = await ctx.decrypt(ctx.publicKey.hex, event.content, "nip4");
|
||||
if (decrypted instanceof Error) {
|
||||
return decrypted;
|
||||
}
|
||||
@ -179,7 +179,7 @@ export class OtherConfig implements PinListGetter, NostrEventAdder {
|
||||
if (event.kind != NostrKind.Encrypted_Custom_App_Data) {
|
||||
return;
|
||||
}
|
||||
const decrypted = await this.ctx.decrypt(this.ctx.publicKey.hex, event.content);
|
||||
const decrypted = await this.ctx.decrypt(this.ctx.publicKey.hex, event.content, "nip44");
|
||||
if (decrypted instanceof Error) {
|
||||
return decrypted;
|
||||
}
|
||||
|
@ -1,8 +1,7 @@
|
||||
import { NostrAccountContext, NostrEvent, NostrKind } from "../../libs/nostr.ts/nostr.ts";
|
||||
import { ConnectionPool, RelayAdder, RelayGetter, RelayRemover } from "../../libs/nostr.ts/relay-pool.ts";
|
||||
import { NostrAccountContext } from "../../libs/nostr.ts/nostr.ts";
|
||||
import { ConnectionPool } from "../../libs/nostr.ts/relay-pool.ts";
|
||||
import { parseJSON } from "../features/profile.ts";
|
||||
import { SingleRelayConnection } from "../../libs/nostr.ts/relay-single.ts";
|
||||
import { RelayConfigChange } from "./setting.tsx";
|
||||
import { blowater, damus } from "../../libs/nostr.ts/relay-list.test.ts";
|
||||
|
||||
export const defaultRelays = [
|
||||
@ -68,20 +67,6 @@ export class RelayConfig {
|
||||
return `${RelayConfig.name}-${ctx.publicKey.bech32()}`;
|
||||
}
|
||||
|
||||
async addEvent(event: NostrEvent<NostrKind.Custom_App_Data>) {
|
||||
const content = await this.ctx.encrypt(this.ctx.publicKey.hex, event.content);
|
||||
if (content instanceof Error) {
|
||||
return content;
|
||||
}
|
||||
const configChange = parseJSON<RelayConfigChange>(content);
|
||||
if (configChange instanceof Error) {
|
||||
return configChange;
|
||||
}
|
||||
if (configChange.type != "RelayConfigChange") {
|
||||
return; // ignore
|
||||
}
|
||||
}
|
||||
|
||||
getRelayURLs() {
|
||||
return new Set(Array.from(this.relayPool.getRelays()).map((r) => r.url));
|
||||
}
|
||||
|
@ -168,7 +168,7 @@ export class GroupMessageController
|
||||
if (groupChatCtx == undefined) {
|
||||
return new Error(`group ${groupAddr} does not have me in it`);
|
||||
}
|
||||
const decryptedContent = await groupChatCtx.decrypt(event.pubkey, event.content);
|
||||
const decryptedContent = await groupChatCtx.decrypt(event.pubkey, event.content, "nip44");
|
||||
if (decryptedContent instanceof Error) {
|
||||
return decryptedContent;
|
||||
}
|
||||
@ -220,7 +220,7 @@ export class GroupMessageController
|
||||
}
|
||||
|
||||
private async handleCreation(event: NostrEvent<NostrKind.Group_Message>) {
|
||||
const decryptedContent = await this.ctx.decrypt(event.pubkey, event.content);
|
||||
const decryptedContent = await this.ctx.decrypt(event.pubkey, event.content, "nip44");
|
||||
if (decryptedContent instanceof Error) {
|
||||
return decryptedContent;
|
||||
}
|
||||
@ -357,7 +357,7 @@ export async function gmEventType(
|
||||
}
|
||||
|
||||
if (ctx.publicKey.hex == event.pubkey) { // I sent
|
||||
if (await ctx.decrypt(receiver, event.content) instanceof Error) {
|
||||
if (await ctx.decrypt(receiver, event.content, "nip44") instanceof Error) {
|
||||
return "gm_message";
|
||||
}
|
||||
return "gm_invitation";
|
||||
@ -408,9 +408,9 @@ export async function decodeInvitation(ctx: NostrAccountContext, event: NostrEve
|
||||
let decryptedContent;
|
||||
const pTags = getTags(event).p;
|
||||
if (pTags.length > 0 && pTags[0] != ctx.publicKey.hex) { // I sent
|
||||
decryptedContent = await ctx.decrypt(pTags[0], event.content);
|
||||
decryptedContent = await ctx.decrypt(pTags[0], event.content, "nip44");
|
||||
} else {
|
||||
decryptedContent = await ctx.decrypt(event.pubkey, event.content);
|
||||
decryptedContent = await ctx.decrypt(event.pubkey, event.content, "nip44");
|
||||
}
|
||||
if (decryptedContent instanceof Error) {
|
||||
return decryptedContent;
|
||||
|
@ -1,14 +1,8 @@
|
||||
import { assertEquals, fail } from "https://deno.land/std@0.176.0/testing/asserts.ts";
|
||||
import {
|
||||
blobToBase64,
|
||||
decryptNostrEvent,
|
||||
InMemoryAccountContext,
|
||||
NostrEvent,
|
||||
NostrKind,
|
||||
} from "../libs/nostr.ts/nostr.ts";
|
||||
import { blobToBase64, InMemoryAccountContext, NostrEvent, NostrKind } from "../libs/nostr.ts/nostr.ts";
|
||||
import { prepareNostrImageEvent, prepareReplyEvent } from "./nostr.ts";
|
||||
import { PrivateKey } from "../libs/nostr.ts/key.ts";
|
||||
import { utf8Decode } from "../libs/nostr.ts/ende.ts";
|
||||
import { utf8Decode } from "../libs/nostr.ts/nip4.ts";
|
||||
import { prepareNormalNostrEvent } from "../libs/nostr.ts/event.ts";
|
||||
|
||||
Deno.test("prepareNostrImageEvent", async (t) => {
|
||||
@ -34,13 +28,12 @@ Deno.test("prepareNostrImageEvent", async (t) => {
|
||||
}
|
||||
|
||||
await t.step("full", async () => {
|
||||
const decryptedEvents = [];
|
||||
const decryptedEvent = await decryptNostrEvent(imgEvent, ctx, pub.hex);
|
||||
if (decryptedEvent instanceof Error) {
|
||||
fail(decryptedEvent.message);
|
||||
const decryptedEvent_content = await ctx.decrypt(imgEvent.pubkey, imgEvent.content);
|
||||
if (decryptedEvent_content instanceof Error) {
|
||||
fail(decryptedEvent_content.message);
|
||||
}
|
||||
decryptedEvents.push(decryptedEvent);
|
||||
assertEquals(await blobToBase64(blob), decryptedEvent.content);
|
||||
|
||||
assertEquals(await blobToBase64(blob), decryptedEvent_content);
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -122,7 +122,7 @@ export async function prepareNostrImageEvent(
|
||||
kind: nostr.NostrKind,
|
||||
): Promise<nostr.NostrEvent | Error> {
|
||||
const binaryContent = await nostr.blobToBase64(blob);
|
||||
const encrypted = await sender.encrypt(receiverPublicKey.hex, binaryContent);
|
||||
const encrypted = await sender.encrypt(receiverPublicKey.hex, binaryContent, "nip44");
|
||||
if (encrypted instanceof Error) {
|
||||
return encrypted;
|
||||
}
|
||||
|
26
deno.lock
26
deno.lock
@ -54,7 +54,15 @@
|
||||
"https://deno.land/x/emit@0.31.0/mod.ts": "326c48e48f3f3c83c11b089aec803e6270bcd64493f250aeb56f46f6960a8458",
|
||||
"https://deno.land/x/wasmbuild@0.14.1/cache.ts": "89eea5f3ce6035a1164b3e655c95f21300498920575ade23161421f5b01967f4",
|
||||
"https://deno.land/x/wasmbuild@0.14.1/loader.ts": "d98d195a715f823151cbc8baa3f32127337628379a02d9eb2a3c5902dbccfc02",
|
||||
"https://esm.sh/@noble/ciphers@0.4.1/chacha": "7a4f831bac30d9ea271916ba892de547c30e0b93bf1034a412a7d443c222fdf5",
|
||||
"https://esm.sh/@noble/ciphers@0.4.1/utils": "dab4bff2315f22a8ac409ddd30c2650ca581fcb050efbf9f01d59e1a377083b1",
|
||||
"https://esm.sh/@noble/curves@1.3.0/secp256k1": "5252f1cfd6e12be71ea2826f76d171458040f168424e59d97a30cc5f54032460",
|
||||
"https://esm.sh/@noble/hashes@1.3.2/utils": "20c519683900b5873b16ff15377049f6e86e183b612a0e442f6acbc056667e6a",
|
||||
"https://esm.sh/@noble/hashes@1.3.3/hkdf": "111a33b0d87213d1b5a7ebf613b0ecd91fc16e3633855862e9a29cf1b87eaee6",
|
||||
"https://esm.sh/@noble/hashes@1.3.3/hmac": "6ff87e80b0bc2bf0720932f0ffb73e780f744faa76b9d62004de8f9469ad1004",
|
||||
"https://esm.sh/@noble/hashes@1.3.3/sha256": "79b93b1d9fc09ebc107b43f6ac5ff39afda60c12dffd673786cb75c756f712fc",
|
||||
"https://esm.sh/@noble/hashes@1.3.3/utils": "cf42cac8548d0c87096c52c693dde2e1ed080e64989ede7ec527b50538236a53",
|
||||
"https://esm.sh/@scure/base@1.1.5": "916e253b1ed0201505202a27209f22d7500f114a303aecd1b76ebcc757df06e6",
|
||||
"https://esm.sh/@scure/bip32@1.3.2": "8f8111ae2b0865644daf69d6b0d8ea76bb15112453f5dc697ba29b44b527b26c",
|
||||
"https://esm.sh/@scure/bip39@1.2.1": "7d6cdfce191281c81406e55de5216714dd22b19790123b652421bbf9718e5057",
|
||||
"https://esm.sh/@scure/bip39@1.2.1/wordlists/english": "c35eb105736c233557d56607751a855ee4685e8097ff0784106d01cf9c81e6b1",
|
||||
@ -78,6 +86,24 @@
|
||||
"https://esm.sh/v134/@scure/bip32@1.3.2/denonext/bip32.mjs": "533695a5fa92d77aed2f0acc23d22c212145d7abd56f5155f0bfd28d2e6b4f7f",
|
||||
"https://esm.sh/v134/@scure/bip39@1.2.1/denonext/bip39.mjs": "2b99a6aac64caae58b2fe1e74576f047b2d787942091f11e3b1a55afa487bd5e",
|
||||
"https://esm.sh/v134/@scure/bip39@1.2.1/denonext/wordlists/english.js": "c606099d820c43e10e7c466571850947405da72f24f9b6bd859685a1610a6840",
|
||||
"https://esm.sh/v135/@noble/ciphers@0.4.1/denonext/_poly1305.js": "74fe8431e8dcf918852eb4e6e04a4471bb5ed078669a2400257fdac4393daee3",
|
||||
"https://esm.sh/v135/@noble/ciphers@0.4.1/denonext/chacha.js": "764a5855210c5043eaa349b0a6c31ad510a0fecc6bc60cfe13f25898d7ebf12d",
|
||||
"https://esm.sh/v135/@noble/ciphers@0.4.1/denonext/utils.js": "46b2c364654930a968e5800cb86d1d467288a2af90d65b251a2d864ff88c66c1",
|
||||
"https://esm.sh/v135/@noble/curves@1.3.0/denonext/_shortw_utils.js": "8d690a8fbb0100093f6ab96457c634465eb4bd79f07adb30bbda5234d189c5e8",
|
||||
"https://esm.sh/v135/@noble/curves@1.3.0/denonext/abstract/curve.js": "280130b0d3e1f15037b449b5870e1f39f5db99f8c310f85a9d4ab129d6dfa583",
|
||||
"https://esm.sh/v135/@noble/curves@1.3.0/denonext/abstract/hash-to-curve.js": "591fb0f81529b2dc9f7ea61a0b988ab659564688ce33bd6c95b0e55c698cb338",
|
||||
"https://esm.sh/v135/@noble/curves@1.3.0/denonext/abstract/modular.js": "f6a63a4725fe208141f87a773ba9485813ffd5291129656fd073f832fbcd4437",
|
||||
"https://esm.sh/v135/@noble/curves@1.3.0/denonext/abstract/utils.js": "0ff50d14245befb0ee4b0eae5f0292acc5fd0f6e5f385195654d7825f0a75669",
|
||||
"https://esm.sh/v135/@noble/curves@1.3.0/denonext/abstract/weierstrass.js": "f97e7a6ecf9f23a864538f7089645c17103f3809134c0bb99c29d56ce824e7b4",
|
||||
"https://esm.sh/v135/@noble/curves@1.3.0/denonext/secp256k1.js": "641ad16ddf79c7f4b69cba4d266078ef21f446cfc3fec83120f6de4f6dee84aa",
|
||||
"https://esm.sh/v135/@noble/hashes@1.3.3/denonext/_assert.js": "f8882bd96e2a6d1834a445c5af97f927b1ba028f34963c8570568e33385c4419",
|
||||
"https://esm.sh/v135/@noble/hashes@1.3.3/denonext/_sha2.js": "7b27807ccd3cf7c3b90ce23b17bc9c5d791a72e41dd2e01a4debd9727990bca9",
|
||||
"https://esm.sh/v135/@noble/hashes@1.3.3/denonext/crypto.js": "cf6efbafcbb35e03bcb3a36cccd3d6d1f9bc4ba23f44a79551929a28c83e7901",
|
||||
"https://esm.sh/v135/@noble/hashes@1.3.3/denonext/hkdf.js": "8266c059351887f60542a555bd9441ccdabf0882256b99ce010b0bf55ca389dd",
|
||||
"https://esm.sh/v135/@noble/hashes@1.3.3/denonext/hmac.js": "c7a0a4fa8e369846713459398dfa1dc373ae5e6fa0eb7280f33dfd3f55a5c8fc",
|
||||
"https://esm.sh/v135/@noble/hashes@1.3.3/denonext/sha256.js": "762e0b0cbde1990fc905eb816d30cdc0cf7dd4c23d123408c6963294f124f97d",
|
||||
"https://esm.sh/v135/@noble/hashes@1.3.3/denonext/utils.js": "701831e12a7e656df467b62f929ac9536ababef1b9b7445c7f87512366ae3933",
|
||||
"https://esm.sh/v135/@scure/base@1.1.5/denonext/base.mjs": "442a66c701330f27adff8b2fa6067308ff9a82b8e178c8482882ff4aa7dfee82",
|
||||
"https://esm.sh/v135/dexie@3.2.4/denonext/dexie.mjs": "1ce1770b71be61358f3bbaf5b0667b395cf30052872e66d312178ebe0a72cca1",
|
||||
"https://esm.sh/v135/dexie@3.2.4/denonext/dist/dexie.js": "20d7fea3aad3a1b5d91b7d43590df26f3132c429b731d2dd77697d2a60f67a79",
|
||||
"https://esm.sh/v135/dexie@3.2.4/dist/dexie.js": "09d2f84b77cc12ac170004634c8560bc7d40a43920ff99166a269a034c48704b",
|
||||
|
@ -1 +1 @@
|
||||
Subproject commit be759ead56a6eb8984e024296f79506b42c89199
|
||||
Subproject commit de91dcf24e41cb95e3b91d525a8beea90e3d4f67
|
Loading…
Reference in New Issue
Block a user