-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add preimage validation + lud-10 support (#2)
* v0.1.1 * feat: add lud-10 support * feat: add preimage validation method * docs: update readme with new helper methods * refactor: update validate preimage method
- Loading branch information
Showing
12 changed files
with
432 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,22 +19,24 @@ yarn add lnurl-pay | |
```js | ||
import { requestInvoice } from 'lnurl-pay' | ||
|
||
const { invoice, params, successAction } = await requestInvoice({ | ||
lnUrlOrAddress: | ||
'lnurl1dp68gurn8ghj7urp0yh8xarpva5kueewvaskcmme9e5k7tewwajkcmpdddhx7amw9akxuatjd3cz7atnv4erqgfuvv5', | ||
tokens: 333, // satoshis | ||
}) | ||
const { invoice, params, successAction, validatePreimage } = | ||
await requestInvoice({ | ||
lnUrlOrAddress: | ||
'lnurl1dp68gurn8ghj7urp0yh8xarpva5kueewvaskcmme9e5k7tewwajkcmpdddhx7amw9akxuatjd3cz7atnv4erqgfuvv5', | ||
tokens: 333, // satoshis | ||
}) | ||
``` | ||
|
||
### Lightning Address | ||
|
||
```js | ||
import { requestInvoice } from 'lnurl-pay' | ||
|
||
const { invoice, params, successAction } = await requestInvoice({ | ||
lnUrlOrAddress: '[email protected]', | ||
tokens: 333, // satoshis | ||
}) | ||
const { invoice, params, successAction, validatePreimage } = | ||
await requestInvoice({ | ||
lnUrlOrAddress: '[email protected]', | ||
tokens: 333, // satoshis | ||
}) | ||
``` | ||
|
||
## Methods | ||
|
@@ -74,6 +76,7 @@ Request an invoice for lnurl o lightning address | |
image: <Metadata base64 image String> | ||
commentAllowed: <Number of characters accepted for the comment query parameter Number> // Default to 0 - not allowed | ||
} | ||
validatePreimage: <validates if preimage param is valid for invoice Function> // (preimage: string) => boolean | ||
} | ||
``` | ||
|
||
|
@@ -166,6 +169,7 @@ Request an invoice for lnurl o lightning address with the given service params ( | |
image: <Metadata base64 image String> | ||
commentAllowed: <Number of characters accepted for the comment query parameter Number> // Default to 0 - not allowed | ||
} | ||
validatePreimage: <validates if preimage param is valid for invoice Function> // (preimage: string) => boolean | ||
} | ||
``` | ||
|
||
|
@@ -186,6 +190,9 @@ const params = await requestInvoiceWithServiceParams({ | |
- [isLightningAddress](#isLightningAddress) - Verify if a string is a lightning adress | ||
- [parseLightningAddress](#parseLightningAddress) - Parse an address and return username and domain | ||
- [isOnionUrl](#isOnionUrl) - Verify if a string is an onion url | ||
- [getHashFromInvoice](#getHashFromInvoice) - Decodes an invoice(string) and get the hash | ||
- [isValidPreimage](#isValidPreimage) - Returns true if the given preimage is valid for invoice | ||
- [decipherAES](#decipherAES) - Decipher ciphertext with a preimage | ||
|
||
## Test | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { getHashFromInvoice } from '../../src/utils' | ||
import { validInvoices, invalidInvoices } from './helper' | ||
|
||
describe('getHashFromInvoice', () => { | ||
test.each(validInvoices)( | ||
'decodes $invoice and get a valid hash', | ||
({ invoice, hash }) => { | ||
expect(getHashFromInvoice(invoice)).toBe(hash) | ||
} | ||
) | ||
|
||
test.each(invalidInvoices)('%s return null', (invoice) => { | ||
expect(getHashFromInvoice(invoice)).toBeFalsy() | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { isValidPreimage } from '../../src/utils' | ||
import { validInvoices, invalidInvoices } from './helper' | ||
|
||
describe('isValidPreimage', () => { | ||
test.each(validInvoices)( | ||
'$preimage is valid for $invoice', | ||
({ invoice, preimage }) => { | ||
expect(isValidPreimage({ invoice, preimage })).toBeTruthy() | ||
} | ||
) | ||
|
||
test.each(validInvoices)('%s return false', ({ invoice }) => { | ||
expect(isValidPreimage({ invoice, preimage: 'some preimage' })).toBeFalsy() | ||
}) | ||
|
||
test.each(invalidInvoices)('%s return false', (invoice) => { | ||
expect(isValidPreimage({ invoice, preimage: 'some preimage' })).toBeFalsy() | ||
}) | ||
}) |
Oops, something went wrong.