Skip to content

Commit

Permalink
WIP: handle unsuccessful nip04 and nip44 encrypt and decrypt messages
Browse files Browse the repository at this point in the history
  • Loading branch information
jchiarulli committed Jan 15, 2025
1 parent c90b697 commit 749abdf
Showing 1 changed file with 26 additions and 4 deletions.
30 changes: 26 additions & 4 deletions ndk-mobile/src/signers/nip55.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,10 +176,16 @@ export class NDKNip55Signer implements NDKSigner {

console.log("intent", intent);

// TODO
// If encryption is unsuccessful, a resultCode of -1 is still returned with the following value in the event, result, and signature properties
// "Could not decrypt the message", ideally a different resultCode, error, or null should be returned
// If the activity operation succeeded
if (intent.resultCode === -1) {
const intentExtra: IntentExtra = intent.extra;
console.log("Signer result:", intentExtra);
if (intentExtra.result === "Could not decrypt the message") {
throw new Error("Encryption failed");
}
return intentExtra.result;
// If the activity operation was canceled, error out
} else if (intent.resultCode === 0) {
Expand Down Expand Up @@ -215,12 +221,17 @@ export class NDKNip55Signer implements NDKSigner {
console.log("intent", intent);

// TODO
// If decryption is unsuccessful, a resultCode of -1 is still returned with the following value in the signature
// "Could not decrypt the message", ideally a different resultCode or error should be returned
// If decryption is unsuccessful, a resultCode of -1 is still returned with the following value in the event, result, and signature properties
// "Could not decrypt the message", ideally a different resultCode, error, or null should be returned
// The encrypted text could be "Could not decrypt the message", so if we error when that is returned we'll be unable
// to decrypt messages containing that text
// If the activity operation succeeded
if (intent.resultCode === -1) {
const intentExtra: IntentExtra = intent.extra;
console.log("Signer result:", intentExtra);
if (intentExtra.result === "Could not decrypt the message") {
throw new Error("Decryption failed");
}
return intentExtra.result;
// If the activity operation was canceled, error out
} else if (intent.resultCode === 0) {
Expand Down Expand Up @@ -255,10 +266,16 @@ export class NDKNip55Signer implements NDKSigner {

console.log("intent", intent);

// TODO
// If encryption is unsuccessful, a resultCode of -1 is still returned with the following value in the event, result, and signature properties
// "Could not decrypt the message", ideally a different resultCode, error, or null should be returned
// If the activity operation succeeded
if (intent.resultCode === -1) {
const intentExtra: IntentExtra = intent.extra;
console.log("Signer result:", intentExtra);
if (intentExtra.result === "Could not decrypt the message") {
throw new Error("Encryption failed");
}
// TODO
// Look into if we need a queue like for NIP-07
// return this.queueNip04("encrypt", recipientHexPubKey, value);
Expand Down Expand Up @@ -297,12 +314,17 @@ export class NDKNip55Signer implements NDKSigner {
console.log("intent", intent);

// TODO
// If decryption is unsuccessful, a resultCode of -1 is still returned with the following value in the signature
// "Could not decrypt the message", ideally a different resultCode or error should be returned
// If decryption is unsuccessful, a resultCode of -1 is still returned with the following value in the event, result, and signature properties
// "Could not decrypt the message", ideally a different resultCode, error, or null should be returned
// The encrypted text could be "Could not decrypt the message", so if we error when that is returned we'll be unable
// to decrypt messages containing that text
// If the activity operation succeeded
if (intent.resultCode === -1) {
const intentExtra: IntentExtra = intent.extra;
console.log("Signer result:", intentExtra);
if (intentExtra.result === "Could not decrypt the message") {
throw new Error("Decryption failed");
}
// TODO
// Look into if we need a queue like for NIP-07
// return this.queueNip04("decrypt", senderHexPubKey, value);
Expand Down

0 comments on commit 749abdf

Please sign in to comment.