forked from jsnbuchanan/crowd-funder-for-time-pwa
update nostr message to include signature for public key
This commit is contained in:
@@ -105,13 +105,11 @@
|
||||
<span class="col-span-1 w-full flex justify-center">{{ zoneName }}</span>
|
||||
</div>
|
||||
|
||||
<div class="flex items-center mb-4">
|
||||
<input
|
||||
type="checkbox"
|
||||
class="mr-2"
|
||||
v-model="includeLocation"
|
||||
@click="includeLocation = !includeLocation"
|
||||
/>
|
||||
<div
|
||||
class="flex items-center mb-4"
|
||||
@click="includeLocation = !includeLocation"
|
||||
>
|
||||
<input type="checkbox" class="mr-2" v-model="includeLocation" />
|
||||
<label for="includeLocation">Include Location</label>
|
||||
</div>
|
||||
<div v-if="includeLocation" class="mb-4 aspect-video">
|
||||
@@ -149,22 +147,12 @@
|
||||
v-if="showGeneralAdvanced && includeLocation"
|
||||
class="items-center mb-4"
|
||||
>
|
||||
<div class="flex">
|
||||
<input
|
||||
type="checkbox"
|
||||
class="mr-2"
|
||||
v-model="sendToTrustroots"
|
||||
@click="sendToTrustroots = !sendToTrustroots"
|
||||
/>
|
||||
<div class="flex" @click="sendToTrustroots = !sendToTrustroots">
|
||||
<input type="checkbox" class="mr-2" v-model="sendToTrustroots" />
|
||||
<label>Send to Trustroots</label>
|
||||
</div>
|
||||
<div class="flex">
|
||||
<input
|
||||
type="checkbox"
|
||||
class="mr-2"
|
||||
v-model="sendToTripHopping"
|
||||
@click="sendToTripHopping = !sendToTripHopping"
|
||||
/>
|
||||
<div class="flex" @click="sendToTripHopping = !sendToTripHopping">
|
||||
<input type="checkbox" class="mr-2" v-model="sendToTripHopping" />
|
||||
<label>Send to TripHopping</label>
|
||||
</div>
|
||||
</div>
|
||||
@@ -202,7 +190,10 @@
|
||||
import "leaflet/dist/leaflet.css";
|
||||
import { AxiosError, AxiosRequestHeaders } from "axios";
|
||||
import { DateTime } from "luxon";
|
||||
import { hexToBytes } from "@noble/hashes/utils";
|
||||
import type { EventTemplate, VerifiedEvent } from "nostr-tools/lib/types/core";
|
||||
import { accountFromSeedWords } from "nostr-tools/nip06";
|
||||
import { finalizeEvent, serializeEvent } from "nostr-tools/pure";
|
||||
import { Component, Vue } from "vue-facing-decorator";
|
||||
import { LMap, LMarker, LTileLayer } from "@vue-leaflet/vue-leaflet";
|
||||
import { Router } from "vue-router";
|
||||
@@ -456,18 +447,25 @@ export default class NewEditProjectView extends Vue {
|
||||
|
||||
const projectPath = encodeURIComponent(resp.data.success.handleId);
|
||||
|
||||
let signedPayload: VerifiedEvent; // sign something to prove ownership of pubkey
|
||||
if (this.sendToTrustroots) {
|
||||
signedPayload = await this.signPayload();
|
||||
this.sendToNostrPartner(
|
||||
"NOSTR-EVENT-TRUSTROOTS",
|
||||
"Trustroots",
|
||||
resp.data.success.claimId,
|
||||
signedPayload,
|
||||
);
|
||||
}
|
||||
if (this.sendToTripHopping) {
|
||||
if (!signedPayload) {
|
||||
signedPayload = await this.signPayload();
|
||||
}
|
||||
this.sendToNostrPartner(
|
||||
"NOSTR-EVENT-TRIPHOPPING",
|
||||
"TripHopping",
|
||||
resp.data.success.claimId,
|
||||
signedPayload,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -535,10 +533,38 @@ export default class NewEditProjectView extends Vue {
|
||||
}
|
||||
}
|
||||
|
||||
private async signPayload(): Promise<VerifiedEvent> {
|
||||
const account = await getAccount(this.activeDid);
|
||||
// get the last number of the derivationPath
|
||||
const finalDerNum = account?.derivationPath?.split?.("/")?.reverse()[0];
|
||||
// remove any trailing '
|
||||
const finalDerNumNoApostrophe = finalDerNum?.replace(/'/g, "");
|
||||
const accountNum = Number(finalDerNumNoApostrophe || 0);
|
||||
const pubPri = accountFromSeedWords(
|
||||
account?.mnemonic as string,
|
||||
"",
|
||||
accountNum,
|
||||
);
|
||||
const privateBytes = hexToBytes(pubPri?.privateKey);
|
||||
// No real content is necessary, we just want something signed,
|
||||
// so we might as well use nostr libs for nostr functions.
|
||||
// Besides: someday we may create real content that we can relay.
|
||||
const event: EventTemplate = {
|
||||
kind: 30402,
|
||||
tags: [[]],
|
||||
content: "",
|
||||
created_at: 0,
|
||||
};
|
||||
// Why does IntelliJ not see matching types?
|
||||
const signedEvent = finalizeEvent(event, privateBytes);
|
||||
return signedEvent;
|
||||
}
|
||||
|
||||
private async sendToNostrPartner(
|
||||
linkCode: string,
|
||||
serviceName: string,
|
||||
jwtId: string,
|
||||
signedPayload: VerifiedEvent,
|
||||
) {
|
||||
// first, get the public key for nostr
|
||||
const account = await getAccount(this.activeDid);
|
||||
@@ -557,11 +583,15 @@ export default class NewEditProjectView extends Vue {
|
||||
const trustrootsUrl = DEFAULT_PARTNER_API_SERVER + "/api/partner/link";
|
||||
const timeSafariUrl = window.location.origin + "/claim/" + jwtId;
|
||||
const content = this.fullClaim.name + " - see " + timeSafariUrl;
|
||||
// Why does IntelliJ not see matching types?
|
||||
const payload = serializeEvent(signedPayload);
|
||||
const trustrootsParams = {
|
||||
jwtId: jwtId,
|
||||
linkCode: linkCode,
|
||||
inputJson: JSON.stringify(content),
|
||||
nostrPubKeyHex: nostrPubKey,
|
||||
pubKeyHex: nostrPubKey,
|
||||
pubKeyImage: payload,
|
||||
pubKeySigHex: signedPayload.sig,
|
||||
};
|
||||
const fullTrustrootsUrl = trustrootsUrl;
|
||||
const headers = await getHeaders(this.activeDid);
|
||||
|
||||
Reference in New Issue
Block a user