From 832e00629925660a1aa7dff90e9a0221c6bda37b Mon Sep 17 00:00:00 2001 From: Roland Bewick Date: Tue, 19 Dec 2023 20:10:46 +0700 Subject: [PATCH] fix: lookup invoice does not return preimage --- package.json | 4 ++-- src/webln/NostrWeblnProvider.ts | 39 +++++++++++++++++++-------------- yarn.lock | 8 +++---- 3 files changed, 29 insertions(+), 22 deletions(-) diff --git a/package.json b/package.json index 44544a2..957cc09 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@getalby/sdk", - "version": "3.2.0", + "version": "3.2.1", "description": "The SDK to integrate with Nostr Wallet Connect and the Alby API", "repository": "https://github.com/getAlby/js-sdk.git", "bugs": "https://github.com/getAlby/js-sdk/issues", @@ -48,7 +48,7 @@ "@types/node": "^20.8.6", "@typescript-eslint/eslint-plugin": "^6.3.0", "@typescript-eslint/parser": "^6.3.0", - "@webbtc/webln-types": "^2.0.1", + "@webbtc/webln-types": "^3.0.0", "browserify": "^17.0.0", "eslint": "^8.46.0", "eslint-config-prettier": "^9.0.0", diff --git a/src/webln/NostrWeblnProvider.ts b/src/webln/NostrWeblnProvider.ts index 93bbd41..1feea40 100644 --- a/src/webln/NostrWeblnProvider.ts +++ b/src/webln/NostrWeblnProvider.ts @@ -36,8 +36,18 @@ const NWCs: Record = { }, }; -// TODO: move to webln-types package -export interface ListTransactionsArgs { +// TODO: review fields (replace with camelCase) and consider move to webln-types package +export type Transaction = Nip47Transaction; + +// TODO: consider moving to webln-types package +export type ListTransactionsResponse = { + transactions: Transaction[]; +}; + +// TODO: consider moving to webln-types package +export type ListTransactionsArgs = Nip47ListTransactionsArgs; + +interface Nip47ListTransactionsArgs { from?: number; until?: number; limit?: number; @@ -46,8 +56,11 @@ export interface ListTransactionsArgs { type?: "incoming" | "outgoing"; } -// TODO: move to webln-types package -export interface Transaction { +type Nip47ListTransactionsResponse = { + transactions: Nip47Transaction[]; +}; + +type Nip47Transaction = { type: string; invoice: string; description: string; @@ -60,12 +73,7 @@ export interface Transaction { created_at: number; expires_at: number; metadata?: Record; -} - -// TODO: move to webln-types package -export interface ListTransactionsResponse { - transactions: Transaction[]; -} +}; interface NostrWebLNOptions { authorizationUrl?: string; // the URL to the NWC interface for the user to confirm the session @@ -89,11 +97,6 @@ type Nip47GetInfoResponse = { methods: string[]; }; -type Nip47ListTransactionsResponse = { - transactions: Nip47Transaction[]; -}; -type Nip47Transaction = Transaction; - type Nip47PayResponse = { preimage: string; }; @@ -392,9 +395,13 @@ export class NostrWebLNProvider implements WebLNProvider, Nip07Provider { return this.executeNip47Request( "lookup_invoice", - args, + { + invoice: args.paymentRequest, + payment_hash: args.paymentHash, + }, (result) => !!result.invoice, (result) => ({ + preimage: result.preimage, paymentRequest: result.invoice, paid: !!result.settled_at, }), diff --git a/yarn.lock b/yarn.lock index ddbbb40..5f1822a 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2211,10 +2211,10 @@ "@typescript-eslint/types" "6.4.0" eslint-visitor-keys "^3.4.1" -"@webbtc/webln-types@^2.0.1": - version "2.0.1" - resolved "https://registry.yarnpkg.com/@webbtc/webln-types/-/webln-types-2.0.1.tgz#760756e2a50e63392c8b3d129b59d172cd11d5dc" - integrity sha512-magyMAiN8u7PsECuj7PfFsStMne30E3QiyNfurL4mTTHse3lmG2Pkh3hDv3jh+D3PTWMfCgv1WFUKVmEgKbBkA== +"@webbtc/webln-types@^3.0.0": + version "3.0.0" + resolved "https://registry.yarnpkg.com/@webbtc/webln-types/-/webln-types-3.0.0.tgz#448b2138423865087ba8859e9e6430fc2463b864" + integrity sha512-aXfTHLKz5lysd+6xTeWl+qHNh/p3qVYbeLo+yDN5cUDmhie2ZoGvkppfWxzbGkcFBzb6dJyQ2/i2cbmDHas+zQ== JSONStream@^1.0.3, JSONStream@^1.3.5: version "1.3.5"