sign_event: return full event instead of only sig

This commit is contained in:
tiero
2023-03-15 20:22:02 +01:00
parent 15c74741ff
commit 43a78776ae
6 changed files with 18 additions and 120 deletions

View File

@@ -76,7 +76,7 @@ const App = () => {
sig: '',
};
event.id = getEventHash(event)
event.sig = await connect.signEvent(event);
event.sig = (await connect.signEvent(event)).sig;
const relay = await connectToRelay('wss://relay.damus.io');
await broadcastToRelay(relay, event, true);

View File

@@ -8,8 +8,7 @@
"build": "parcel build --public-url /connect index.html"
},
"dependencies": {
"@nostr-connect/connect": "^0.2.3",
"nostr-tools": "^1.6.0",
"@nostr-connect/connect": "../src",
"qrcode.react": "^3.1.0",
"react": "^18.2.0",
"react-app-polyfill": "^1.0.0",

View File

@@ -144,43 +144,8 @@
resolved "https://registry.yarnpkg.com/@msgpackr-extract/msgpackr-extract-win32-x64/-/msgpackr-extract-win32-x64-2.2.0.tgz#016d855b6bc459fd908095811f6826e45dd4ba64"
integrity sha512-XrC0JzsqQSvOyM3t04FMLO6z5gCuhPE6k4FXuLK5xf52ZbdvcFe1yBmo7meCew9B8G2f0T9iu9t3kfTYRYROgA==
"@noble/hashes@1.0.0":
version "1.0.0"
resolved "https://registry.yarnpkg.com/@noble/hashes/-/hashes-1.0.0.tgz#d5e38bfbdaba174805a4e649f13be9a9ed3351ae"
integrity sha512-DZVbtY62kc3kkBtMHqwCOfXrT/hnoORy5BJ4+HU1IR59X0KWAOqsfzQPcUl/lQLlG7qXbe/fZ3r/emxtAl+sqg==
"@noble/hashes@^0.5.7":
version "0.5.9"
resolved "https://registry.yarnpkg.com/@noble/hashes/-/hashes-0.5.9.tgz#9f3051a4cc6f7c168022b3b7fbbe9fe2a35cccf0"
integrity sha512-7lN1Qh6d8DUGmfN36XRsbN/WcGIPNtTGhkw26vWId/DlCIGsYJJootTtPGghTLcn/AaXPx2Q0b3cacrwXa7OVw==
"@noble/hashes@~1.1.1", "@noble/hashes@~1.1.3":
version "1.1.5"
resolved "https://registry.yarnpkg.com/@noble/hashes/-/hashes-1.1.5.tgz#1a0377f3b9020efe2fae03290bd2a12140c95c11"
integrity sha512-LTMZiiLc+V4v1Yi16TD6aX2gmtKszNye0pQgbaLqkvhIqP7nVsSaJsWloGQjJfJ8offaoP5GtX3yY5swbcJxxQ==
"@noble/hashes@~1.2.0":
version "1.2.0"
resolved "https://registry.yarnpkg.com/@noble/hashes/-/hashes-1.2.0.tgz#a3150eeb09cc7ab207ebf6d7b9ad311a9bdbed12"
integrity sha512-FZfhjEDbT5GRswV3C6uvLPHMiVD6lQBmpoX5+eSiPaMTXte/IKqI5dykDxzZB/WBeK/CDuQRBWarPdi3FNY2zQ==
"@noble/secp256k1@^1.7.0", "@noble/secp256k1@~1.7.0":
version "1.7.0"
resolved "https://registry.yarnpkg.com/@noble/secp256k1/-/secp256k1-1.7.0.tgz#d15357f7c227e751d90aa06b05a0e5cf993ba8c1"
integrity sha512-kbacwGSsH/CTout0ZnZWxnW1B+jH/7r/WAAKLBtrRJ/+CUH7lgmQzl3GTrQua3SGKWNSDsS6lmjnDpIJ5Dxyaw==
"@noble/secp256k1@^1.7.1":
version "1.7.1"
resolved "https://registry.yarnpkg.com/@noble/secp256k1/-/secp256k1-1.7.1.tgz#b251c70f824ce3ca7f8dc3df08d58f005cc0507c"
integrity sha512-hOUk6AyBFmqVrv7k5WAw/LpszxVbj9gGN4JRkIX52fdFAj1UA61KXmZDvqVEm+pOyec3+fIeZB02LYa/pWOArw==
"@nostr-connect/connect@^0.2.3":
version "0.2.3"
resolved "https://registry.yarnpkg.com/@nostr-connect/connect/-/connect-0.2.3.tgz#6e7ba032dea5b853a3e272a61eebb5f2fed9c14b"
integrity sha512-04zMTyL+L9lic7MS6O5jvqTcFzh1wAj6Onj89uRsVbM89D8QlEAD4xYAFfAy6dIHL0LHAj1s6eRZUIiJbyPdbg==
dependencies:
events "^3.3.0"
nostr-tools "^1.0.1"
"@nostr-connect/connect@../src":
version "0.0.0"
"@parcel/bundler-default@2.8.2":
version "2.8.2"
@@ -741,45 +706,6 @@
chrome-trace-event "^1.0.2"
nullthrows "^1.1.1"
"@scure/base@^1.1.1", "@scure/base@~1.1.0":
version "1.1.1"
resolved "https://registry.yarnpkg.com/@scure/base/-/base-1.1.1.tgz#ebb651ee52ff84f420097055f4bf46cfba403938"
integrity sha512-ZxOhsSyxYwLJj3pLZCefNitxsj093tb2vq90mp2txoYeBqbcjDjqFhyM8eUjq/uFm6zJ+mUuqxlS2FkuSY1MTA==
"@scure/bip32@^1.1.1":
version "1.1.1"
resolved "https://registry.yarnpkg.com/@scure/bip32/-/bip32-1.1.1.tgz#f62e4a2f13cc3e5e720ad81b7582b8631ae6835a"
integrity sha512-UmI+liY7np2XakaW+6lMB6HZnpczWk1yXZTxvg8TM8MdOcKHCGL1YkraGj8eAjPfMwFNiAyek2hXmS/XFbab8g==
dependencies:
"@noble/hashes" "~1.1.3"
"@noble/secp256k1" "~1.7.0"
"@scure/base" "~1.1.0"
"@scure/bip32@^1.1.5":
version "1.1.5"
resolved "https://registry.yarnpkg.com/@scure/bip32/-/bip32-1.1.5.tgz#d2ccae16dcc2e75bc1d75f5ef3c66a338d1ba300"
integrity sha512-XyNh1rB0SkEqd3tXcXMi+Xe1fvg+kUIcoRIEujP1Jgv7DqW2r9lg3Ah0NkFaCs9sTkQAQA8kw7xiRXzENi9Rtw==
dependencies:
"@noble/hashes" "~1.2.0"
"@noble/secp256k1" "~1.7.0"
"@scure/base" "~1.1.0"
"@scure/bip39@^1.1.0":
version "1.1.0"
resolved "https://registry.yarnpkg.com/@scure/bip39/-/bip39-1.1.0.tgz#92f11d095bae025f166bef3defcc5bf4945d419a"
integrity sha512-pwrPOS16VeTKg98dYXQyIjJEcWfz7/1YJIwxUEPFfQPtc86Ym/1sVgQ2RLoD43AazMk2l/unK4ITySSpW2+82w==
dependencies:
"@noble/hashes" "~1.1.1"
"@scure/base" "~1.1.0"
"@scure/bip39@^1.1.1":
version "1.1.1"
resolved "https://registry.yarnpkg.com/@scure/bip39/-/bip39-1.1.1.tgz#b54557b2e86214319405db819c4b6a370cf340c5"
integrity sha512-t+wDck2rVkh65Hmv280fYdVdY25J9YeEUIgn2LG1WM6gxFkGzcksoDiUkWVpVp3Oex9xGC68JU2dSbUfwZ2jPg==
dependencies:
"@noble/hashes" "~1.2.0"
"@scure/base" "~1.1.0"
"@swc/helpers@^0.4.12":
version "0.4.14"
resolved "https://registry.yarnpkg.com/@swc/helpers/-/helpers-0.4.14.tgz#1352ac6d95e3617ccb7c1498ff019654f1e12a74"
@@ -1079,7 +1005,7 @@ escape-string-regexp@^1.0.5:
resolved "https://registry.yarnpkg.com/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz#1b61c0562190a8dff6ae3bb2cf0200ca130b86d4"
integrity sha512-vbRorB5FUQWvla16U8R/qgaFIya2qGzwDrNmCZuYKrbdSUMG6I1ZCGQRefkRVhuOkIGVne7BQ35DSfo1qvJqFg==
events@^3.1.0, events@^3.3.0:
events@^3.1.0:
version "3.3.0"
resolved "https://registry.yarnpkg.com/events/-/events-3.3.0.tgz#31a95ad0a924e2d2c419a813aeb2c4e878ea7400"
integrity sha512-mQw+2fkQbALzQ7V0MY0IqdnXNOeTtP4r0lN9z7AAawCXgqea7bDii20AYrIBrFd/Hx0M2Ocz6S111CaFkUcb0Q==
@@ -1300,29 +1226,6 @@ node-releases@^2.0.6:
resolved "https://registry.yarnpkg.com/node-releases/-/node-releases-2.0.8.tgz#0f349cdc8fcfa39a92ac0be9bc48b7706292b9ae"
integrity sha512-dFSmB8fFHEH/s81Xi+Y/15DQY6VHW81nXRj86EMSL3lmuTmK1e+aT4wrFCkTbm+gSwkw4KpX+rT/pMM2c1mF+A==
nostr-tools@^1.0.1:
version "1.1.1"
resolved "https://registry.yarnpkg.com/nostr-tools/-/nostr-tools-1.1.1.tgz#2be4cd650bc0a4d20650b6cf46fee451c9f565b8"
integrity sha512-mxgjbHR6nx2ACBNa2tBpeM/glsPWqxHPT1Kszx/XfzL+kUdi1Gm3Xz1UcaODQ2F84IFtCKNLO+aF31ZfTAhSYQ==
dependencies:
"@noble/hashes" "^0.5.7"
"@noble/secp256k1" "^1.7.0"
"@scure/base" "^1.1.1"
"@scure/bip32" "^1.1.1"
"@scure/bip39" "^1.1.0"
nostr-tools@^1.6.0:
version "1.6.0"
resolved "https://registry.yarnpkg.com/nostr-tools/-/nostr-tools-1.6.0.tgz#4052fe717a378982c8ce56d39986089abacfc6d3"
integrity sha512-qjjJQ7YxJUMzgS24eVlxkZ87PKJtU6dlH04OzVuK6w+GSPL+VdUZkMe2lfSpnb7OkCrDIzmbFbtx+Q4LXdU2xw==
dependencies:
"@noble/hashes" "1.0.0"
"@noble/secp256k1" "^1.7.1"
"@scure/base" "^1.1.1"
"@scure/bip32" "^1.1.5"
"@scure/bip39" "^1.1.1"
prettier "^2.8.4"
nth-check@^2.0.1:
version "2.1.1"
resolved "https://registry.yarnpkg.com/nth-check/-/nth-check-2.1.1.tgz#c9eab428effce36cd6b92c924bdb000ef1f1ed1d"
@@ -1436,11 +1339,6 @@ posthtml@^0.16.4, posthtml@^0.16.5:
posthtml-parser "^0.11.0"
posthtml-render "^3.0.0"
prettier@^2.8.4:
version "2.8.4"
resolved "https://registry.yarnpkg.com/prettier/-/prettier-2.8.4.tgz#34dd2595629bfbb79d344ac4a91ff948694463c3"
integrity sha512-vIS4Rlc2FNh0BySk3Wkd6xmwxB0FpOndW5fisM5H8hsZSxU2VWVB5CWIkIjWvrHjIhxk2g3bfMKM87zNTrZddw==
process@^0.11.10:
version "0.11.10"
resolved "https://registry.yarnpkg.com/process/-/process-0.11.10.tgz#7332300e840161bda3e69a1d1d91a7d4bc16f182"

View File

@@ -61,6 +61,6 @@
},
"dependencies": {
"events": "^3.3.0",
"nostr-tools": "^1.6.0"
"nostr-tools": "^1.7.4"
}
}

View File

@@ -1,11 +1,12 @@
import EventEmitter from 'events';
import { Event, getPublicKey, nip04, Kind } from 'nostr-tools';
import { nip26 } from 'nostr-tools';
import { isValidRequest, NostrRPC } from './rpc';
export interface Metadata {
name: string;
url: string;
url?: string;
description?: string;
icons?: string[];
}
@@ -218,10 +219,10 @@ export class Connect {
pubkey: string;
content: string;
created_at: number;
}): Promise<string> {
}): Promise<Event> {
if (!this.target) throw new Error('Not connected');
const signature = await this.rpc.call({
const eventWithSig = await this.rpc.call({
target: this.target,
request: {
method: 'sign_event',
@@ -229,7 +230,7 @@ export class Connect {
},
});
return signature as string;
return eventWithSig as Event;
}
async describe(): Promise<string[]> {
@@ -252,7 +253,7 @@ export class Connect {
until?: number | TimeRanges;
since?: number | TimeRanges;
}
): Promise<string> {
): Promise<nip26.Delegation> {
if (!this.target) throw new Error('Not connected');
if (conditions.until && typeof conditions.until !== 'number') {
@@ -270,14 +271,14 @@ export class Connect {
conditions.since = TimeRangeToUnix[conditions.since];
}
const sig = await this.rpc.call({
const delegation = await this.rpc.call({
target: this.target,
request: {
method: 'delegate',
params: [delegatee, conditions],
},
});
return sig as string;
return delegation as nip26.Delegation;
}
async getRelays(): Promise<{

View File

@@ -4901,10 +4901,10 @@ normalize-path@^3.0.0, normalize-path@~3.0.0:
resolved "https://registry.yarnpkg.com/normalize-path/-/normalize-path-3.0.0.tgz#0dcd69ff23a1c9b11fd0978316644a0388216a65"
integrity sha512-6eZs5Ls3WtCisHWp9S2GUy8dqkpGi4BVSz3GaqiE6ezub0512ESztXUwUB6C6IKbQkY2Pnb/mD4WYojCRwcwLA==
nostr-tools@^1.6.0:
version "1.6.0"
resolved "https://registry.yarnpkg.com/nostr-tools/-/nostr-tools-1.6.0.tgz#4052fe717a378982c8ce56d39986089abacfc6d3"
integrity sha512-qjjJQ7YxJUMzgS24eVlxkZ87PKJtU6dlH04OzVuK6w+GSPL+VdUZkMe2lfSpnb7OkCrDIzmbFbtx+Q4LXdU2xw==
nostr-tools@^1.7.4:
version "1.7.4"
resolved "https://registry.yarnpkg.com/nostr-tools/-/nostr-tools-1.7.4.tgz#8f14ffde8f6674c3758bb49207a1ee4227a4b9fe"
integrity sha512-YowDJ+S3UW9KCYPDZfZXXMITrJSMjiCmFOK5HohyKkg+w6EipFUTkFRBPRA2BTLXO/qw8gukKXfL0B7Dv3jtcQ==
dependencies:
"@noble/hashes" "1.0.0"
"@noble/secp256k1" "^1.7.1"