Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
"lodash.merge": "^4.6.2",
"lodash.pick": "^4.4.0",
"lodash.snakecase": "^4.1.1",
"nostr-tools": "^1.17.0",
"nostr-tools": "^2.23.5",
"pubsub-js": "^1.9.5",
"react": "^19.2.6",
"react-confetti": "^6.4.0",
Expand Down
70 changes: 38 additions & 32 deletions src/extension/background-script/connectors/lawallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { Method } from "axios";
import lightningPayReq from "bolt11-signet";
import Hex from "crypto-js/enc-hex";
import sha256 from "crypto-js/sha256";
import { nip04, relayInit, type Relay } from "nostr-tools";
import { nip04, Relay } from "nostr-tools";
import { Event, EventKind } from "~/extension/providers/nostr/types";
import { Account } from "~/types";

Expand Down Expand Up @@ -68,7 +68,7 @@ export default class LaWallet implements Connector {
this.account = account;
this.config = config;
this.public_key = new Nostr(config.privateKey).getPublicKey();
this.relay = relayInit(config.relayUrl);
this.relay = new Relay(config.relayUrl);
}

async init() {
Expand Down Expand Up @@ -248,39 +248,45 @@ export default class LaWallet implements Connector {

await this.relay.connect();
return new Promise((resolve, reject) => {
const sub = this.relay.sub([
this.relay.subscribe(
[
{
authors: [this.config.ledgerPublicKey, this.config.urlxPublicKey],
"#e": [event.id!],
"#t": [
"internal-transaction-error",
"internal-transaction-ok",
"outbound-transaction-start",
],
},
],
{
authors: [this.config.ledgerPublicKey, this.config.urlxPublicKey],
"#e": [event.id!],
"#t": [
"internal-transaction-error",
"internal-transaction-ok",
"outbound-transaction-start",
],
},
]);

sub.on("event", async (event) => {
const tag = event.tags.find((tag) => tag[0] === "t")![1];
const content = JSON.parse(event.content);
switch (tag) {
case "internal-transaction-ok": // Refund
if (event.tags[1][1] === this.public_key && !!content.memo) {
return reject(new Error(content.memo));
onevent: async (event) => {
const tag = event.tags.find((tag) => tag[0] === "t")![1];
const content = JSON.parse(event.content);
switch (tag) {
case "internal-transaction-ok": // Refund
if (event.tags[1][1] === this.public_key && !!content.memo) {
return reject(new Error(content.memo));
}
break;
case "internal-transaction-error": // No funds or ledger error
return reject(new Error(content.messages[0]));
case "outbound-transaction-start": // Payment done
return resolve({
data: {
preimage: await extractPreimage(
event,
this.config.privateKey
),
paymentHash: paymentRequestDetails.tagsObject.payment_hash!,
route: payment_route,
},
});
}
break;
case "internal-transaction-error": // No funds or ledger error
return reject(new Error(content.messages[0]));
case "outbound-transaction-start": // Payment done
return resolve({
data: {
preimage: await extractPreimage(event, this.config.privateKey),
paymentHash: paymentRequestDetails.tagsObject.payment_hash!,
route: payment_route,
},
});
},
}
});
);
});
}

Expand Down
53 changes: 1 addition & 52 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1349,11 +1349,6 @@
strict-event-emitter "^0.2.4"
web-encoding "^1.1.5"

"@noble/ciphers@0.2.0":
version "0.2.0"
resolved "https://registry.yarnpkg.com/@noble/ciphers/-/ciphers-0.2.0.tgz#a12cda60f3cf1ab5d7c77068c3711d2366649ed7"
integrity sha512-6YBxJDAapHSdd3bLDv6x2wRPwq4QFMUaB3HvljNBUTThDd12eSm7/3F+2lnfzx2jvM+S6Nsy0jEt9QbPqSwqRw==

"@noble/ciphers@2.1.1":
version "2.1.1"
resolved "https://registry.yarnpkg.com/@noble/ciphers/-/ciphers-2.1.1.tgz#c8c74fcda8c3d1f88797d0ecda24f9fc8b92b052"
Expand All @@ -1364,13 +1359,6 @@
resolved "https://registry.yarnpkg.com/@noble/ciphers/-/ciphers-2.2.0.tgz#84fb45ac9332925d643b80f89ceb0ea2f21dba95"
integrity sha512-Z6pjIZ/8IJcCGzb2S/0Px5J81yij85xASuk1teLNeg75bfT07MV3a/O2Mtn1I2se43k3lkVEcFaR10N4cgQcZA==

"@noble/curves@1.1.0", "@noble/curves@~1.1.0":
version "1.1.0"
resolved "https://registry.npmjs.org/@noble/curves/-/curves-1.1.0.tgz"
integrity sha512-091oBExgENk/kGj3AZmtBDMpxQPDtxQABR2B9lb1JbVTs6ytdzZNwvhxQ4MWasRNEzlbEH8jCWFCwhF/Obj5AA==
dependencies:
"@noble/hashes" "1.3.1"

"@noble/curves@2.0.1":
version "2.0.1"
resolved "https://registry.yarnpkg.com/@noble/curves/-/curves-2.0.1.tgz#64ba8bd5e8564a02942655602515646df1cdb3ad"
Expand All @@ -1385,11 +1373,6 @@
dependencies:
"@noble/hashes" "1.8.0"

"@noble/hashes@1.3.1", "@noble/hashes@~1.3.0", "@noble/hashes@~1.3.1":
version "1.3.1"
resolved "https://registry.npmjs.org/@noble/hashes/-/hashes-1.3.1.tgz"
integrity sha512-EbqwksQwz9xDRGfDST86whPBgM65E0OH/pCgqW0GBVzO22bNE+NuIbeTb714+IfSjU3aRk47EUvXIb5bTsenKA==

"@noble/hashes@1.4.0":
version "1.4.0"
resolved "https://registry.yarnpkg.com/@noble/hashes/-/hashes-1.4.0.tgz#45814aa329f30e4fe0ba49426f49dfccdd066426"
Expand Down Expand Up @@ -1681,11 +1664,6 @@
resolved "https://registry.yarnpkg.com/@remix-run/router/-/router-1.15.3.tgz#d2509048d69dbb72d5389a14945339f1430b2d3c"
integrity sha512-Oy8rmScVrVxWZVOpEF57ovlnhpZ8CCPlnIIumVcV9nFdiSIrus99+Lw78ekXyGvVDlIsFJbSfmSovJUhCWYV3w==

"@scure/base@1.1.1", "@scure/base@~1.1.0":
version "1.1.1"
resolved "https://registry.npmjs.org/@scure/base/-/base-1.1.1.tgz"
integrity sha512-ZxOhsSyxYwLJj3pLZCefNitxsj093tb2vq90mp2txoYeBqbcjDjqFhyM8eUjq/uFm6zJ+mUuqxlS2FkuSY1MTA==

"@scure/base@2.0.0":
version "2.0.0"
resolved "https://registry.yarnpkg.com/@scure/base/-/base-2.0.0.tgz#ba6371fddf92c2727e88ad6ab485db6e624f9a98"
Expand All @@ -1701,15 +1679,6 @@
resolved "https://registry.yarnpkg.com/@scure/base/-/base-1.2.5.tgz#f9d1b232425b367d0dcb81c96611dcc651d58671"
integrity sha512-9rE6EOVeIQzt5TSu4v+K523F8u6DhBsoZWPGKlnCshhlDhy0kJzUX4V+tr2dWmzF1GdekvThABoEQBGBQI7xZw==

"@scure/bip32@1.3.1":
version "1.3.1"
resolved "https://registry.npmjs.org/@scure/bip32/-/bip32-1.3.1.tgz"
integrity sha512-osvveYtyzdEVbt3OfwwXFr4P2iVBL5u1Q3q4ONBfDY/UpOuXmOlbgwc1xECEboY8wIays8Yt6onaWMUdUbfl0A==
dependencies:
"@noble/curves" "~1.1.0"
"@noble/hashes" "~1.3.1"
"@scure/base" "~1.1.0"

"@scure/bip32@2.0.1":
version "2.0.1"
resolved "https://registry.yarnpkg.com/@scure/bip32/-/bip32-2.0.1.tgz#4ceea207cee8626d3fe8f0b6ab68b6af8f81c482"
Expand All @@ -1728,14 +1697,6 @@
"@noble/hashes" "~1.8.0"
"@scure/base" "~1.2.5"

"@scure/bip39@1.2.1":
version "1.2.1"
resolved "https://registry.npmjs.org/@scure/bip39/-/bip39-1.2.1.tgz"
integrity sha512-Z3/Fsz1yr904dduJD0NpiyRHhRYHdcnyh73FZWiV+/qhWi83wNJ3NWolYqCEN+ZWsUz2TWwajJggcRE9r1zUYg==
dependencies:
"@noble/hashes" "~1.3.0"
"@scure/base" "~1.1.0"

"@scure/bip39@2.0.1":
version "2.0.1"
resolved "https://registry.yarnpkg.com/@scure/bip39/-/bip39-2.0.1.tgz#47a6dc15e04faf200041239d46ae3bb7c3c96add"
Expand Down Expand Up @@ -8491,19 +8452,7 @@ normalize-range@^0.1.2:
resolved "https://registry.npmjs.org/normalize-range/-/normalize-range-0.1.2.tgz"
integrity "sha1-LRDAa9/TEuqXd2laTShDlFa3WUI= sha512-bdok/XvKII3nUpklnV6P2hxtMNrCboOjAcyBuQnWEhO665FwrSNRxU+AqpsyvO6LgGYPspN+lu5CLtw4jPRKNA=="

nostr-tools@^1.17.0:
version "1.17.0"
resolved "https://registry.yarnpkg.com/nostr-tools/-/nostr-tools-1.17.0.tgz#b6f62e32fedfd9e68ec0a7ce57f74c44fc768e8c"
integrity sha512-LZmR8GEWKZeElbFV5Xte75dOeE9EFUW/QLI1Ncn3JKn0kFddDKEfBbFN8Mu4TMs+L4HR/WTPha2l+PPuRnJcMw==
dependencies:
"@noble/ciphers" "0.2.0"
"@noble/curves" "1.1.0"
"@noble/hashes" "1.3.1"
"@scure/base" "1.1.1"
"@scure/bip32" "1.3.1"
"@scure/bip39" "1.2.1"

nostr-tools@^2.23.3:
nostr-tools@^2.23.3, nostr-tools@^2.23.5:
version "2.23.5"
resolved "https://registry.yarnpkg.com/nostr-tools/-/nostr-tools-2.23.5.tgz#46fa68a35cf6e918c4f59208a2ed7585c72a68a0"
integrity sha512-Fa7ZlUdjfUW1P4E7H3yBexhOHYi18XNyvd2n7eNHkYR085xADX6Y8V8Vm7nT/XQajaFOBrptXmVIGkJ2E4vfVw==
Expand Down
Loading