Event JSON
{
"id": "77e463538e247f28f1433510998fc67dd33ff7f7ee53eec7453e351ac826a501",
"pubkey": "a008def15796fba9a0d6fab04e8fd57089285d9fd505da5a83fe8aad57a3564d",
"created_at": 1731501834,
"kind": 1617,
"tags": [
[
"a",
"30617:68d81165918100b7da43fc28f7d1fc12554466e1115886b9e7bb326f65ec4272:rust-nostr"
],
[
"r",
"73f7c34fd424cae57a0da1be1f5fd31d9b8075c0"
],
[
"r",
"151f0abb89e6ded8fa60557ca9d3c2469a68ce47"
],
[
"alt",
"git patch: connect: prevent err after `set_user_public_key`"
],
[
"t",
"root"
],
[
"branch-name",
"nostr-signer-prevent-set_user_public_key-err"
],
[
"p",
"68d81165918100b7da43fc28f7d1fc12554466e1115886b9e7bb326f65ec4272"
],
[
"commit",
"151f0abb89e6ded8fa60557ca9d3c2469a68ce47"
],
[
"parent-commit",
"ce05916f4acef2351e6ab648e4e7296a6d10f8d9"
],
[
"commit-pgp-sig",
"-----BEGIN PGP SIGNATURE-----\n\niQIzBAABCAAdFiEEsRaN4Kb3mvfPwNXpaOFUhtc/deEFAmc0nNoACgkQaOFUhtc/\ndeGqEw//a34XyEi7xysRMKo1P+mbtdggiGleeLHp1abrFRg35j+F2kXcRs8Bc2cW\n/movmVi5yysAKTfPuYq6MRblGhXalFz22LS8couK5ObBxvfrnlaQbJtvUFYgA25z\nsnuyGYqomQxpU74e97vBIW8Vbk2euWsi8dZMdFird8gUl4sQV6hil8632gYSC+Fh\n+Ut7eFpuk+AXNknbmD3eVSLMAowkW4N1HfmPfSGzs7C8j+ZbKk9IuZNCh/I7Dnr8\nht00aeFP6K5+0E63+qCBRTSYSAcQYiuNR8xfvQG0yTUOdW+XkKSS66tTzZsGgGxI\nvFJBWpHBNB5ODoj0IuWEYeNaIHBSnEkG3cp2S4YRIjZUtIZjlOG9eyKgsLAiEWUD\nAHbYnAQctNGiymO72pibdOhUEEQf5BXJjs0dy74Up1LUu5zINxZy+HsLnciH4AqW\nVrJOZeBoxRKYvsf0ehrUVyyWZNtPZkjukxwdbXoLi+OHatSqDlF+7oaBlOi4SpWS\nlW/SsDjJaIy6/OVzDC5rs5kiz4NiQk2gKybMYnB+xxeQamaJO51NkbQ4Zp93nNO6\nr7Zz+V+WB+xFRT8TEv1uz6O/ZRVsHr1tvBUwVqvKnRc+iu0eulIP0pLNDe3y0zQp\n+S38/Qyfoj+1ptcGw+cwQHcIASsnoILxeGczGiPFVDdyhhx247w=\n=qtl2\n-----END PGP SIGNATURE-----"
],
[
"description",
"connect: prevent err after `set_user_public_key`\n\nprevent bootstrap from resulting in an error when triggered after\n`set_user_public_key` is called. eg.\n```\nlet signer = NostrConnect::new(...);\nsigner.set_user_public_key(pk);\n// first usage of signer will trigger bootstrap eg:\nsigner.sign_event(e);\n```\n\nthrow a error during bootstrap if the remote signer public key is\ndifferent to the value given to `set_user_public_key`. this would\nhappen in the unlikely event that the remote signer was reconfigured\nto use the same app keys with a user key\n"
],
[
"author",
"DanConwayDev",
"DanConwayDev@protonmail.com",
"1731501261",
"0"
],
[
"committer",
"DanConwayDev",
"DanConwayDev@protonmail.com",
"1731501261",
"0"
]
],
"content": "From 151f0abb89e6ded8fa60557ca9d3c2469a68ce47 Mon Sep 17 00:00:00 2001\nFrom: DanConwayDev \u003cDanConwayDev@protonmail.com\u003e\nDate: Wed, 13 Nov 2024 12:34:21 +0000\nSubject: [PATCH] connect: prevent err after `set_user_public_key`\n\nprevent bootstrap from resulting in an error when triggered after\n`set_user_public_key` is called. eg.\n```\nlet signer = NostrConnect::new(...);\nsigner.set_user_public_key(pk);\n// first usage of signer will trigger bootstrap eg:\nsigner.sign_event(e);\n```\n\nthrow a error during bootstrap if the remote signer public key is\ndifferent to the value given to `set_user_public_key`. this would\nhappen in the unlikely event that the remote signer was reconfigured\nto use the same app keys with a user key\n---\n crates/nostr-connect/src/client.rs | 8 +++++++-\n crates/nostr-connect/src/error.rs | 3 +++\n 2 files changed, 10 insertions(+), 1 deletion(-)\n\ndiff --git a/crates/nostr-connect/src/client.rs b/crates/nostr-connect/src/client.rs\nindex 6bae456..c0dfffb 100644\n--- a/crates/nostr-connect/src/client.rs\n+++ b/crates/nostr-connect/src/client.rs\n@@ -127,7 +127,13 @@ impl NostrConnect {\n GetRemoteSignerPublicKey::RemoteOnly(public_key) =\u003e public_key,\n GetRemoteSignerPublicKey::WithUserPublicKey { remote, user } =\u003e {\n // Set user public key\n- self.user_public_key.set(user)?; // This shouldn't fails\n+ if let Some(stored_user_public_key) = self.user_public_key.get() {\n+ if !user.eq(stored_user_public_key) {\n+ return Err(Error::UserPublicKeyChanged(stored_user_public_key, user))\n+ }\n+ } else {\n+ self.user_public_key.set(user)?; // This shouldn't fails\n+ }\n \n // Return remote signer public key\n remote\ndiff --git a/crates/nostr-connect/src/error.rs b/crates/nostr-connect/src/error.rs\nindex 8a63543..8c6f2ba 100644\n--- a/crates/nostr-connect/src/error.rs\n+++ b/crates/nostr-connect/src/error.rs\n@@ -37,6 +37,9 @@ pub enum Error {\n /// Set user public key error\n #[error(transparent)]\n SetUserPublicKey(#[from] SetError\u003cPublicKey\u003e),\n+ /// User public key has changed\n+ #[error(\"user public key changed from: {0} to: {1}\")]\n+ UserPublicKeyChanged(PublicKey, PublicKey),\n /// NIP46 response error\n #[error(\"response error: {0}\")]\n Response(String),\n--\nlibgit2 1.8.1\n\n",
"sig": "3571837083c569271bba9a20a9d8cfb0a0a00adbf71d56a43a05073218b5336f7b79ae28b710661b4727958900fc292b38566dc6ce4283bd1dfa8c6040607bb2"
}