@lnurlcash/kit 0.14.0-rc.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +16 -0
- package/LICENSE +22 -0
- package/MIGRATION-0.14.md +63 -0
- package/README.md +90 -0
- package/RELEASING.md +64 -0
- package/SECURITY.md +14 -0
- package/THREAT-MODEL.md +44 -0
- package/dist/index.d.ts +275 -0
- package/dist/index.js +1231 -0
- package/package.json +71 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## 0.14.0 - unreleased
|
|
4
|
+
|
|
5
|
+
- Publish the protocol library maintained and exercised by `lnurl-wallet`
|
|
6
|
+
directly from the wallet repository.
|
|
7
|
+
- Include LN address registration and recovery scanning, Part 2 public-key
|
|
8
|
+
notes, configurable transports, offline note verification, fee handling,
|
|
9
|
+
and bound mint receipts.
|
|
10
|
+
- Replace the separate pre-0.14 `lnurlcash-kit` implementation with the scoped
|
|
11
|
+
`@lnurlcash/kit` package. This is an intentional package-name and API
|
|
12
|
+
boundary: callers must change their dependency and imports, then review the
|
|
13
|
+
exported surface before upgrading from `lnurlcash-kit@0.13.x`.
|
|
14
|
+
|
|
15
|
+
Existing `lnurlcash-kit` installations are unaffected and do not select the
|
|
16
|
+
new scoped package.
|
package/LICENSE
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 dni
|
|
4
|
+
Copyright (c) 2026 TheCryptoDonkey
|
|
5
|
+
|
|
6
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
8
|
+
in the Software without restriction, including without limitation the rights
|
|
9
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
11
|
+
furnished to do so, subject to the following conditions:
|
|
12
|
+
|
|
13
|
+
The above copyright notice and this permission notice shall be included in all
|
|
14
|
+
copies or substantial portions of the Software.
|
|
15
|
+
|
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
+
SOFTWARE.
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
# Migrating from 0.13
|
|
2
|
+
|
|
3
|
+
Version 0.14 makes the protocol layer maintained by `lnurl-wallet` the npm
|
|
4
|
+
package implementation. It is published as `@lnurlcash/kit`; npm treats that
|
|
5
|
+
as a different package from `lnurlcash-kit`. Upgrade only after changing the
|
|
6
|
+
dependency and imports, adapting the API and testing the caller.
|
|
7
|
+
|
|
8
|
+
```sh
|
|
9
|
+
npm uninstall lnurlcash-kit
|
|
10
|
+
npm install --save-exact @lnurlcash/kit@0.14.0
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Configuration
|
|
14
|
+
|
|
15
|
+
The old package accepted `LnurlcashOptions` on each request and offered
|
|
16
|
+
`createClient(options)`. Version 0.14 configures its process-wide hooks once:
|
|
17
|
+
|
|
18
|
+
```ts
|
|
19
|
+
import {
|
|
20
|
+
configureNetworkGuard,
|
|
21
|
+
configureTransport,
|
|
22
|
+
configureSecretProvider,
|
|
23
|
+
configurePubkeySecretProvider
|
|
24
|
+
} from '@lnurlcash/kit'
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
Do this during application startup, before any request. The defaults use
|
|
28
|
+
platform `fetch`, admit requests, generate legacy outputs using Web Crypto and
|
|
29
|
+
do not generate Part 2 public-key outputs.
|
|
30
|
+
|
|
31
|
+
## Removed high-level helpers
|
|
32
|
+
|
|
33
|
+
The following 0.13 APIs are not part of the wallet protocol layer and are not
|
|
34
|
+
exported by 0.14:
|
|
35
|
+
|
|
36
|
+
- `createClient` and `LnurlcashOptions`
|
|
37
|
+
- `settleNoteForValue`
|
|
38
|
+
- `restoreNotes` and `restoreFromSeed`
|
|
39
|
+
- seed/root derivation helpers from `cash.ts`
|
|
40
|
+
- payment-request encoding and decoding from the old `request.ts`
|
|
41
|
+
- UI fee strings `formatFeePercent` and `describeMintFee`
|
|
42
|
+
|
|
43
|
+
Keep `lnurlcash-kit@0.13.x` pinned if a caller still depends on them. Seed
|
|
44
|
+
persistence, restoration and UI wording remain wallet policy rather than
|
|
45
|
+
protocol-package policy.
|
|
46
|
+
|
|
47
|
+
## Errors and mutations
|
|
48
|
+
|
|
49
|
+
The wallet implementation exports `ServiceError`, `AmbiguousMintError` and
|
|
50
|
+
`AmbiguousMutationError` alongside typed spent, unknown and pending errors.
|
|
51
|
+
Review existing error handling instead of matching messages or assuming the
|
|
52
|
+
old class hierarchy.
|
|
53
|
+
|
|
54
|
+
Mutation functions use the configured secret providers and return the wallet's
|
|
55
|
+
current result shapes. Re-test every path that persists replacement outputs,
|
|
56
|
+
especially ambiguous results, before moving value with 0.14.
|
|
57
|
+
|
|
58
|
+
## New surface
|
|
59
|
+
|
|
60
|
+
Version 0.14 adds the wallet's current Part 2 and LN address work, including
|
|
61
|
+
`fetchNoteInfoByPubkey`, cp1/ck1/cs1/cx1 codecs and derivation,
|
|
62
|
+
`registerUsername`, `scanForAddressNotes`, `configureTransport` and
|
|
63
|
+
bound-mint receipt validation.
|
package/README.md
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
# @lnurlcash/kit
|
|
2
|
+
|
|
3
|
+
The LNURLcash protocol client used by
|
|
4
|
+
[`lnurl-wallet`](https://github.com/lnurlcash/lnurl-wallet). It is published
|
|
5
|
+
from the wallet repository so the reference wallet and the npm package share
|
|
6
|
+
the same implementation and test suite.
|
|
7
|
+
|
|
8
|
+
LUD-25 is still a draft. Pin an exact version and review the changelog before
|
|
9
|
+
upgrading software that can spend bearer notes.
|
|
10
|
+
|
|
11
|
+
Version 0.14 replaces the separate `lnurlcash-kit` 0.13 implementation under a
|
|
12
|
+
new scoped package name. Existing consumers should read
|
|
13
|
+
[MIGRATION-0.14.md](./MIGRATION-0.14.md) before upgrading.
|
|
14
|
+
|
|
15
|
+
## Install
|
|
16
|
+
|
|
17
|
+
```sh
|
|
18
|
+
npm install --save-exact @lnurlcash/kit
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
Node 22 or newer is required. The package is ESM-only and also targets modern
|
|
22
|
+
browsers with Web Crypto and `AbortSignal.timeout`.
|
|
23
|
+
|
|
24
|
+
## Use
|
|
25
|
+
|
|
26
|
+
```ts
|
|
27
|
+
import {fetchNoteInfo, rotateNote} from '@lnurlcash/kit'
|
|
28
|
+
|
|
29
|
+
const info = await fetchNoteInfo(noteUrl)
|
|
30
|
+
const replacement = await rotateNote(info.callback, info.k1)
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
`fetchNoteInfo` first uses a secret-free hash or public-key lookup. It sends a
|
|
34
|
+
raw legacy `k1` only when an older service explicitly says that `k1` is
|
|
35
|
+
required. Mutations generate and name replacement outputs locally.
|
|
36
|
+
|
|
37
|
+
Configuration is process-wide. Call `configureNetworkGuard`,
|
|
38
|
+
`configureTransport`, `configureSecretProvider` and
|
|
39
|
+
`configurePubkeySecretProvider` once during application startup, before any
|
|
40
|
+
requests are made. The defaults use the platform `fetch` and secure random
|
|
41
|
+
bytes; the wallet overrides them for offline mode, recoverable outputs and
|
|
42
|
+
host-provided transports.
|
|
43
|
+
|
|
44
|
+
## Public modules
|
|
45
|
+
|
|
46
|
+
The root export includes:
|
|
47
|
+
|
|
48
|
+
- LNURL and note parsing in `urls.ts`
|
|
49
|
+
- BOLT-11 amount, hash and preimage checks in `bolt11.ts`
|
|
50
|
+
- offline note signatures and Part 2 ownership proofs in `signature.ts`
|
|
51
|
+
- fee parsing and arithmetic in `fees.ts`
|
|
52
|
+
- guarded network access in `net.ts`
|
|
53
|
+
- note lookup, melt, rotate, split, merge and settlement in `request.ts`
|
|
54
|
+
- mint invoice and bound-receipt checks in `mintRequest.ts`
|
|
55
|
+
- LN address registration and gap-limit recovery scans in `addresses.ts`
|
|
56
|
+
- cp1, ck1, cs1 and cx1 codecs and derivation in `recoverableNotes.ts`
|
|
57
|
+
- injectable output-secret providers in `secrets.ts`
|
|
58
|
+
|
|
59
|
+
The implementation has no dependency on Solid, browser storage or any other
|
|
60
|
+
wallet module. Wallet policy stays in the parent `src/lnurlcash.ts` adapter.
|
|
61
|
+
|
|
62
|
+
## Errors and ambiguous mutations
|
|
63
|
+
|
|
64
|
+
LNURLcash mutations move bearer value. A timeout or unreadable response does
|
|
65
|
+
not prove that a callback failed. Preserve every replacement secret carried by
|
|
66
|
+
an `AmbiguousMutationError` and reconcile the input and outputs before retrying.
|
|
67
|
+
Do not turn transport uncertainty into an automatic retry.
|
|
68
|
+
|
|
69
|
+
See [THREAT-MODEL.md](./THREAT-MODEL.md) before integrating the package and
|
|
70
|
+
[SECURITY.md](./SECURITY.md) before reporting a vulnerability.
|
|
71
|
+
|
|
72
|
+
## Development
|
|
73
|
+
|
|
74
|
+
From `src/lib` in the wallet checkout:
|
|
75
|
+
|
|
76
|
+
```sh
|
|
77
|
+
npm ci
|
|
78
|
+
npm run check
|
|
79
|
+
npm pack --dry-run
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
The package and wallet share a version. A wallet tag named `vX.Y.Z` publishes
|
|
83
|
+
`@lnurlcash/kit@X.Y.Z` from the same commit through
|
|
84
|
+
`.github/workflows/release-kit.yml` and npm trusted publishing; releases must
|
|
85
|
+
not be published from a maintainer workstation. The one-time scoped-package
|
|
86
|
+
bootstrap is documented in [RELEASING.md](./RELEASING.md).
|
|
87
|
+
|
|
88
|
+
## Licence
|
|
89
|
+
|
|
90
|
+
MIT
|
package/RELEASING.md
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
# Releasing @lnurlcash/kit
|
|
2
|
+
|
|
3
|
+
The final package is published from `lnurlcash/lnurl-wallet`, not from a
|
|
4
|
+
workstation and not from the old standalone kit repository.
|
|
5
|
+
|
|
6
|
+
## One-time scoped-package bootstrap
|
|
7
|
+
|
|
8
|
+
npm cannot configure a trusted publisher until the package exists. After this
|
|
9
|
+
package source has been reviewed and merged, an `lnurlcash` npm organisation
|
|
10
|
+
owner must make the one exceptional manual publish:
|
|
11
|
+
|
|
12
|
+
1. Build, test and pack the merged source from a disposable clean checkout,
|
|
13
|
+
changing only its package version to `0.14.0-rc.0`.
|
|
14
|
+
2. Publish that tarball as a public prerelease with
|
|
15
|
+
`npm publish --access public --tag next <tarball>`.
|
|
16
|
+
3. Verify that npm shows `@lnurlcash/kit@0.14.0-rc.0` under the `next` tag and
|
|
17
|
+
that no `latest` tag has been created.
|
|
18
|
+
|
|
19
|
+
Do not manually publish `0.14.0`: that version is reserved for the reviewed
|
|
20
|
+
OIDC release. The prerelease only creates the scoped package so its trusted
|
|
21
|
+
publisher can be configured; do not recommend it to production consumers.
|
|
22
|
+
|
|
23
|
+
## One-time trusted-publisher setup
|
|
24
|
+
|
|
25
|
+
An npm package owner must configure the trusted publisher for
|
|
26
|
+
`@lnurlcash/kit` as:
|
|
27
|
+
|
|
28
|
+
- provider: GitHub Actions
|
|
29
|
+
- organisation or user: `lnurlcash`
|
|
30
|
+
- repository: `lnurl-wallet`
|
|
31
|
+
- workflow: `release-kit.yml`
|
|
32
|
+
- environment: `npm-publish`
|
|
33
|
+
- allowed actions: enable direct `npm publish`
|
|
34
|
+
|
|
35
|
+
A GitHub repository or organisation administrator should create the
|
|
36
|
+
`npm-publish` environment, restrict it to `v*` tags and require a maintainer
|
|
37
|
+
review. No npm token or GPG key belongs in GitHub secrets; npm uses the
|
|
38
|
+
workflow's short-lived OIDC identity and records provenance.
|
|
39
|
+
|
|
40
|
+
Do not create a final release until both sides are configured. A missing or
|
|
41
|
+
mismatched trusted publisher should fail closed, but it is not a useful release
|
|
42
|
+
rehearsal.
|
|
43
|
+
|
|
44
|
+
## Each release
|
|
45
|
+
|
|
46
|
+
1. Choose the next version for both the wallet and kit, then update the kit's
|
|
47
|
+
`package.json` and `CHANGELOG.md` in a reviewed pull request.
|
|
48
|
+
2. Require the wallet CI and the independent `src/lib` package gate to pass.
|
|
49
|
+
3. Merge, then create the shared `vX.Y.Z` tag at that exact merge commit. The
|
|
50
|
+
tag must exactly equal `v` plus the version in `src/lib/package.json`.
|
|
51
|
+
4. Pushing the tag starts both release workflows. The wallet is tested and
|
|
52
|
+
deployed at `X.Y.Z`; `release-kit.yml` independently rebuilds and tests the
|
|
53
|
+
package, packs one tarball, performs a dry-run publish and uploads that same
|
|
54
|
+
tarball through npm OIDC as `@lnurlcash/kit@X.Y.Z`.
|
|
55
|
+
5. Verify the workflow, npm version, repository metadata and provenance before
|
|
56
|
+
announcing the release.
|
|
57
|
+
|
|
58
|
+
There is no separate package release train: the wallet tag is the compatibility
|
|
59
|
+
signal for both artefacts. A manual workflow dispatch validates only by default;
|
|
60
|
+
its separate `publish` input must be deliberately enabled to reach npm.
|
|
61
|
+
|
|
62
|
+
Version 0.14 is a package-name and API boundary from the old standalone
|
|
63
|
+
implementation. Check `MIGRATION-0.14.md` and test each consumer before
|
|
64
|
+
replacing its pinned dependency.
|
package/SECURITY.md
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
# Security policy
|
|
2
|
+
|
|
3
|
+
Only the latest release is supported while LUD-25 remains a draft. Consumers
|
|
4
|
+
should pin an exact package version and review protocol changes before
|
|
5
|
+
upgrading.
|
|
6
|
+
|
|
7
|
+
Report vulnerabilities privately through the
|
|
8
|
+
[lnurl-wallet security advisory form](https://github.com/lnurlcash/lnurl-wallet/security/advisories/new).
|
|
9
|
+
Do not open a public issue for anything that could leak, steal, duplicate or
|
|
10
|
+
destroy a note.
|
|
11
|
+
|
|
12
|
+
Include the affected version, a minimal reproduction and the consequence where
|
|
13
|
+
possible. Protocol concerns should also be raised on the
|
|
14
|
+
[LUD-25 proposal](https://github.com/lnurl/luds/pull/301).
|
package/THREAT-MODEL.md
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
# Threat model
|
|
2
|
+
|
|
3
|
+
`@lnurlcash/kit` handles LNURLcash protocol data. It does not provide custody,
|
|
4
|
+
secret storage, routing, channel management or a guarantee that a mint will
|
|
5
|
+
honour its liabilities.
|
|
6
|
+
|
|
7
|
+
## Assets and trust boundaries
|
|
8
|
+
|
|
9
|
+
- A note secret is a bearer instrument. Anyone who obtains it can spend it.
|
|
10
|
+
- A replacement secret may be the only authority over an output after an
|
|
11
|
+
ambiguous mutation. Callers must persist it before treating a request as
|
|
12
|
+
safely retryable.
|
|
13
|
+
- A mint public key is not secret, but accepting the wrong key defeats offline
|
|
14
|
+
verification. Applications must pin and review service identity changes.
|
|
15
|
+
- The mint is trusted with custody. Its signed statements prove what it said;
|
|
16
|
+
they do not prove reserves, settlement or future redemption.
|
|
17
|
+
|
|
18
|
+
## Defences in this package
|
|
19
|
+
|
|
20
|
+
- Mutations name replacement outputs by hash or derived public key rather than
|
|
21
|
+
disclosing the replacement secret.
|
|
22
|
+
- Network admission rejects unsafe service URLs and applies the configured
|
|
23
|
+
guard before requests are made.
|
|
24
|
+
- Informational responses are checked against the requested note identity.
|
|
25
|
+
- Mint signatures bind note identity and value for offline verification.
|
|
26
|
+
- Amounts, invoices, preimages, fees and bound-mint receipts are validated
|
|
27
|
+
before their results are accepted.
|
|
28
|
+
- Ambiguous request outcomes remain distinct from requests known not to have
|
|
29
|
+
left the process.
|
|
30
|
+
|
|
31
|
+
## Caller responsibilities
|
|
32
|
+
|
|
33
|
+
- Encrypt note secrets and backups at rest, exclude them from logs, analytics
|
|
34
|
+
and crash reports, and use a cryptographically secure secret provider.
|
|
35
|
+
- Treat callback requests as mutations. Do not retry after a timeout or an
|
|
36
|
+
unreadable response until the newly named outputs have been reconciled.
|
|
37
|
+
- Pin trusted service origins and signing keys outside this stateless package.
|
|
38
|
+
- Route traffic appropriately if service-side timing and address correlation
|
|
39
|
+
are a concern.
|
|
40
|
+
- Rotate newly minted bearer notes promptly: invoice preimages may have been
|
|
41
|
+
visible to the service or to anyone able to observe invoice verification.
|
|
42
|
+
|
|
43
|
+
The complete wallet adds storage, recovery and user-confirmation policy around
|
|
44
|
+
these primitives. Those controls are not part of the npm package.
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,275 @@
|
|
|
1
|
+
declare class AmbiguousMintError extends Error {
|
|
2
|
+
}
|
|
3
|
+
declare class AmbiguousMutationError extends AmbiguousMintError {
|
|
4
|
+
readonly newSecrets: string[];
|
|
5
|
+
constructor(message: string, newSecrets: string[]);
|
|
6
|
+
}
|
|
7
|
+
declare class ServiceError extends Error {
|
|
8
|
+
readonly reason: string;
|
|
9
|
+
constructor(reason: string);
|
|
10
|
+
}
|
|
11
|
+
declare class PendingNoteError extends Error {
|
|
12
|
+
constructor();
|
|
13
|
+
}
|
|
14
|
+
declare class NoteSpentError extends Error {
|
|
15
|
+
constructor(reason: string);
|
|
16
|
+
}
|
|
17
|
+
declare class NoteUnknownError extends Error {
|
|
18
|
+
constructor(reason: string);
|
|
19
|
+
}
|
|
20
|
+
declare const classifyNoteError: (err: Error) => Error;
|
|
21
|
+
|
|
22
|
+
declare const isBech32Lnurl: (data: string) => boolean;
|
|
23
|
+
declare const toBech32Lnurl: (url: string) => string;
|
|
24
|
+
declare const fromBech32Lnurl: (data: string) => string | null;
|
|
25
|
+
declare const defaultSchemeFor: (hostish: string) => "http" | "https";
|
|
26
|
+
declare const isAllowedServiceUrl: (value: string) => boolean;
|
|
27
|
+
declare const fromLud17: (url: string) => string;
|
|
28
|
+
declare const toLud17w: (url: string) => string;
|
|
29
|
+
declare const isLightningAddress: (value: string) => boolean;
|
|
30
|
+
declare const resolveMintInput: (value: string) => string | null;
|
|
31
|
+
declare const mintAddressUrl: (payUrl: string) => string | null;
|
|
32
|
+
declare const lightningAddressUsername: (payUrl: string) => string | null;
|
|
33
|
+
declare const resolveLnurlInput: (value: string) => string | null;
|
|
34
|
+
declare const noteK1: (url: string) => string | null;
|
|
35
|
+
declare const requireNoteK1: (url: string) => string;
|
|
36
|
+
declare const noteDeclaredAmount: (url: string) => number | null;
|
|
37
|
+
declare const noteSignature: (url: string) => string | null;
|
|
38
|
+
declare const isValidK1: (value: string) => boolean;
|
|
39
|
+
declare const resolveNoteInput: (value: string) => string | null;
|
|
40
|
+
declare const isValidNoteInput: (value: string) => boolean;
|
|
41
|
+
declare const buildNoteUrl: (withdrawLink: string, k1: string, amountMsat?: number) => string;
|
|
42
|
+
declare const withNewK1: (url: string, k1: string, amountMsat: number, signature?: string) => string;
|
|
43
|
+
declare const withoutK1: (url: string, amountMsat: number, signature?: string) => string;
|
|
44
|
+
declare const withoutSignature: (url: string) => string;
|
|
45
|
+
declare const serverOf: (url: string) => string;
|
|
46
|
+
declare const serviceOriginOf: (value: string) => string;
|
|
47
|
+
declare const noteEndpointOf: (url: string) => string;
|
|
48
|
+
|
|
49
|
+
declare const sameInvoice: (a: string, b: string) => boolean;
|
|
50
|
+
declare const isPreimage: (value: string) => boolean;
|
|
51
|
+
declare const isBolt11Invoice: (value: string) => boolean;
|
|
52
|
+
declare const encodeBolt11AmountSuffix: (amountMsat: number) => string;
|
|
53
|
+
declare const decodeBolt11AmountSuffix: (suffix: string) => number | null;
|
|
54
|
+
declare const decodeBolt11AmountMsat: (pr: string) => number | null;
|
|
55
|
+
declare const decodeBolt11PaymentHash: (pr: string) => string | null;
|
|
56
|
+
declare const verifyMeltPreimage: (pr: string, preimage: string) => boolean;
|
|
57
|
+
|
|
58
|
+
declare const MINT_PUBKEY_PATTERN: RegExp;
|
|
59
|
+
declare const NOTE_SIGNATURE_PATTERN: RegExp;
|
|
60
|
+
declare const parseMintKey: (body: any) => {
|
|
61
|
+
mintPubkey: string;
|
|
62
|
+
};
|
|
63
|
+
declare const hashK1: (k1: string) => string;
|
|
64
|
+
declare const verifyNoteSignature: (k1: string, amountMsat: number, signatureHex: string, mintPubkeyHex: string) => boolean;
|
|
65
|
+
declare const verifyNoteSignatureHash: (h: string, amountMsat: number, signatureHex: string, mintPubkeyHex: string) => boolean;
|
|
66
|
+
declare const signNoteOwnership: (secretKey: Uint8Array) => Uint8Array;
|
|
67
|
+
declare const recoverNoteOwnershipPubkey: (signature: Uint8Array) => Uint8Array | null;
|
|
68
|
+
type AddressProofAction = 'register' | 'unregister';
|
|
69
|
+
declare const signAddressProof: (branchIndexZeroSecretKey: Uint8Array, action: AddressProofAction, username: string) => Uint8Array;
|
|
70
|
+
declare const cp1FromCk1: (ck1: string) => string | null;
|
|
71
|
+
declare const requireMutationSignature: (body: any, field: "sig" | "sig2") => string;
|
|
72
|
+
|
|
73
|
+
type MintFee = {
|
|
74
|
+
baseFeeMsat: number;
|
|
75
|
+
feePpm: number;
|
|
76
|
+
};
|
|
77
|
+
declare const MIN_COMMENT_LENGTH_FOR_SECRET = 64;
|
|
78
|
+
type PayRequestCommentInfo = {
|
|
79
|
+
commentAllowed?: number;
|
|
80
|
+
};
|
|
81
|
+
declare const canUseMintComment: (info: PayRequestCommentInfo) => boolean;
|
|
82
|
+
declare const requireMintComment: (info: PayRequestCommentInfo) => void;
|
|
83
|
+
declare const parseMintFee: (metadata: string) => MintFee | null;
|
|
84
|
+
declare const applyMintFee: (grossMsat: number, fee: MintFee) => number;
|
|
85
|
+
declare const withinMintFeeBand: (grossMsat: number, netMsat: number, fee: MintFee) => boolean;
|
|
86
|
+
declare const grossUpForMintFee: (netMsat: number, fee: MintFee) => number;
|
|
87
|
+
|
|
88
|
+
type NetworkGuard = () => void;
|
|
89
|
+
declare const configureNetworkGuard: (guard: NetworkGuard) => void;
|
|
90
|
+
type Transport = (url: string, signal: AbortSignal, method: string) => Promise<Response>;
|
|
91
|
+
declare const configureTransport: (next: Transport) => void;
|
|
92
|
+
declare const lnurlFetch: (url: string | URL, method?: string) => Promise<any>;
|
|
93
|
+
|
|
94
|
+
type WithdrawRequestInfo = {
|
|
95
|
+
tag: 'withdrawRequest';
|
|
96
|
+
callback: string;
|
|
97
|
+
k1: string;
|
|
98
|
+
minWithdrawable: number;
|
|
99
|
+
maxWithdrawable: number;
|
|
100
|
+
defaultDescription?: string;
|
|
101
|
+
mintPubkey: string;
|
|
102
|
+
sig?: string;
|
|
103
|
+
};
|
|
104
|
+
type HashWithdrawRequestInfo = Omit<WithdrawRequestInfo, 'k1'>;
|
|
105
|
+
declare const fetchNoteInfoByHash: (url: string, h: string) => Promise<HashWithdrawRequestInfo>;
|
|
106
|
+
declare const fetchNoteInfoByPubkey: (url: string, cp1Value: string) => Promise<HashWithdrawRequestInfo>;
|
|
107
|
+
declare const fetchNoteInfo: (url: string) => Promise<WithdrawRequestInfo>;
|
|
108
|
+
declare const probeBurnedNote: (url: string) => Promise<"live" | "gone" | "unknown">;
|
|
109
|
+
type MintAddressInfo = {
|
|
110
|
+
tag: 'withdrawRequest';
|
|
111
|
+
callback: string;
|
|
112
|
+
minWithdrawable: number;
|
|
113
|
+
maxWithdrawable: number;
|
|
114
|
+
defaultDescription?: string;
|
|
115
|
+
mintPubkey: string;
|
|
116
|
+
nodePubkey?: string;
|
|
117
|
+
payLink: string;
|
|
118
|
+
nodeAlias?: string;
|
|
119
|
+
nodeUri?: string;
|
|
120
|
+
nodeColor?: string;
|
|
121
|
+
nodeCapacityMsat?: number;
|
|
122
|
+
nodeNumChannels?: number;
|
|
123
|
+
nodeNumPeers?: number;
|
|
124
|
+
sunsetDate?: string;
|
|
125
|
+
outstandingNotesMsat?: number;
|
|
126
|
+
};
|
|
127
|
+
declare const fetchMintAddress: (url: string) => Promise<MintAddressInfo>;
|
|
128
|
+
type WithdrawSuccessResponse = {
|
|
129
|
+
status: 'OK';
|
|
130
|
+
sig?: string;
|
|
131
|
+
sig2?: string;
|
|
132
|
+
pr?: string;
|
|
133
|
+
verify?: string;
|
|
134
|
+
};
|
|
135
|
+
type MeltResult = {
|
|
136
|
+
verify?: string;
|
|
137
|
+
pr?: string;
|
|
138
|
+
};
|
|
139
|
+
declare const meltNote: (callback: string, k1: string, pr: string) => Promise<MeltResult>;
|
|
140
|
+
type HashedMutationResult = {
|
|
141
|
+
signature: string;
|
|
142
|
+
};
|
|
143
|
+
declare const rotateNoteWithHash: (callback: string, k1: string, h: string) => Promise<HashedMutationResult>;
|
|
144
|
+
type HashedSplitResult = {
|
|
145
|
+
signature: string;
|
|
146
|
+
changeSignature: string;
|
|
147
|
+
};
|
|
148
|
+
declare const splitNoteWithHash: (callback: string, k1s: string[], amountMsat: number, h: string, h2: string) => Promise<HashedSplitResult>;
|
|
149
|
+
declare const mergeNotesWithHash: (callback: string, k1s: string[], h: string) => Promise<HashedMutationResult>;
|
|
150
|
+
type RotateResult = {
|
|
151
|
+
k1: string;
|
|
152
|
+
signature: string;
|
|
153
|
+
};
|
|
154
|
+
declare const generateOutputSecret: (domain: string, preferPubkey: boolean) => string;
|
|
155
|
+
declare const disclosedValue: (secret: string) => string;
|
|
156
|
+
declare const rotateNote: (callback: string, k1: string) => Promise<RotateResult>;
|
|
157
|
+
type SplitResult = {
|
|
158
|
+
k1: string;
|
|
159
|
+
signature: string;
|
|
160
|
+
change: string;
|
|
161
|
+
changeSignature: string;
|
|
162
|
+
};
|
|
163
|
+
declare const splitNote: (callback: string, k1s: string[], amountMsat: number) => Promise<SplitResult>;
|
|
164
|
+
declare const mergeNotes: (callback: string, k1s: string[]) => Promise<RotateResult>;
|
|
165
|
+
type SettledNote = {
|
|
166
|
+
k1: string;
|
|
167
|
+
amountMsat: number;
|
|
168
|
+
signature?: string;
|
|
169
|
+
callback: string;
|
|
170
|
+
};
|
|
171
|
+
declare const settleNote: (baseUrl: string, k1: string, expectedAmountMsat: number, signature: string | undefined) => Promise<SettledNote>;
|
|
172
|
+
|
|
173
|
+
declare const encodeCp1: (pubkeyXOnly: Uint8Array) => string;
|
|
174
|
+
declare const decodeCp1: (value: string) => Uint8Array | null;
|
|
175
|
+
declare const isCp1: (value: string) => boolean;
|
|
176
|
+
declare const encodeCk1: (signature: Uint8Array) => string;
|
|
177
|
+
declare const decodeCk1: (value: string) => Uint8Array | null;
|
|
178
|
+
declare const isCk1: (value: string) => boolean;
|
|
179
|
+
declare const encodeCs1: (signature: Uint8Array) => string;
|
|
180
|
+
declare const decodeCs1: (value: string) => Uint8Array | null;
|
|
181
|
+
declare const isCs1: (value: string) => boolean;
|
|
182
|
+
declare const encodeCs1WithAmount: (amountMsat: number, signature: Uint8Array) => string;
|
|
183
|
+
declare const decodeCs1WithAmount: (value: string) => {
|
|
184
|
+
amountMsat: number;
|
|
185
|
+
signature: Uint8Array;
|
|
186
|
+
} | null;
|
|
187
|
+
declare const isCs1WithAmount: (value: string) => boolean;
|
|
188
|
+
declare const decodeAnyCs1: (value: string) => Uint8Array | null;
|
|
189
|
+
declare const isAnyCs1: (value: string) => boolean;
|
|
190
|
+
type Cx1 = {
|
|
191
|
+
pubkeyXOnly: Uint8Array;
|
|
192
|
+
chainCode: Uint8Array;
|
|
193
|
+
};
|
|
194
|
+
declare const encodeCx1: (pubkeyXOnly: Uint8Array, chainCode: Uint8Array) => string;
|
|
195
|
+
declare const decodeCx1: (value: string) => Cx1 | null;
|
|
196
|
+
declare const isCx1: (value: string) => boolean;
|
|
197
|
+
declare const deriveNotePubkey: (branchPubkeyXOnly: Uint8Array, chainCode: Uint8Array, index: number) => Uint8Array;
|
|
198
|
+
declare const deriveNoteSecretKey: (branchPrivateKey: Uint8Array, chainCode: Uint8Array, index: number) => Uint8Array;
|
|
199
|
+
|
|
200
|
+
type InternalTransferHint = {
|
|
201
|
+
cx1: Cx1;
|
|
202
|
+
startIndex: number;
|
|
203
|
+
};
|
|
204
|
+
declare const parseInternalTransferHint: (metadata: string) => InternalTransferHint | null;
|
|
205
|
+
type InternalTransferResult = {
|
|
206
|
+
kind: 'merge';
|
|
207
|
+
index: number;
|
|
208
|
+
signature: string;
|
|
209
|
+
} | {
|
|
210
|
+
kind: 'split';
|
|
211
|
+
index: number;
|
|
212
|
+
signature: string;
|
|
213
|
+
change: string;
|
|
214
|
+
changeSignature: string;
|
|
215
|
+
};
|
|
216
|
+
declare const payInternalTransfer: (callback: string, k1s: string[], amountMsat: number, totalInputMsat: number, hint: InternalTransferHint) => Promise<InternalTransferResult>;
|
|
217
|
+
|
|
218
|
+
type PayRequestInfo = {
|
|
219
|
+
tag: 'payRequest';
|
|
220
|
+
callback: string;
|
|
221
|
+
minSendable: number;
|
|
222
|
+
maxSendable: number;
|
|
223
|
+
metadata: string;
|
|
224
|
+
withdrawLink?: string;
|
|
225
|
+
mintPubkey?: string;
|
|
226
|
+
mintFee?: MintFee;
|
|
227
|
+
commentAllowed?: number;
|
|
228
|
+
mintToHash?: boolean;
|
|
229
|
+
internalTransfer?: InternalTransferHint;
|
|
230
|
+
};
|
|
231
|
+
declare const fetchPayRequest: (url: string) => Promise<PayRequestInfo>;
|
|
232
|
+
type BoundMintCommitment = {
|
|
233
|
+
h: string;
|
|
234
|
+
amountMsat: number;
|
|
235
|
+
signature?: string;
|
|
236
|
+
};
|
|
237
|
+
type InvoiceResult = {
|
|
238
|
+
pr: string;
|
|
239
|
+
verify?: string;
|
|
240
|
+
disposable: boolean;
|
|
241
|
+
mintToHash: boolean;
|
|
242
|
+
mint?: BoundMintCommitment;
|
|
243
|
+
};
|
|
244
|
+
declare const requestInvoice: (payCallback: string, amountMsat: number, outputHash?: string) => Promise<InvoiceResult>;
|
|
245
|
+
type VerifyResult = {
|
|
246
|
+
settled: boolean;
|
|
247
|
+
preimage: string | null;
|
|
248
|
+
pr: string;
|
|
249
|
+
mint?: BoundMintCommitment;
|
|
250
|
+
};
|
|
251
|
+
declare const fetchInvoiceVerification: (verifyUrl: string) => Promise<VerifyResult>;
|
|
252
|
+
declare const requireBoundMintQuote: (invoice: InvoiceResult, expectedH: string, grossMsat: number, fee?: MintFee) => BoundMintCommitment;
|
|
253
|
+
declare const validateBoundMintReceipt: (invoice: InvoiceResult, verification: VerifyResult, expectedH: string, expectedAmountMsat: number, mintPubkey: string) => Required<BoundMintCommitment>;
|
|
254
|
+
|
|
255
|
+
declare const registerUsername: (server: string, username: string, cx1: string, indexZeroSecretKey: Uint8Array) => Promise<void>;
|
|
256
|
+
declare const unregisterUsername: (server: string, username: string, indexZeroSecretKey: Uint8Array) => Promise<void>;
|
|
257
|
+
type AddressScanResult = {
|
|
258
|
+
index: number;
|
|
259
|
+
cp1: string;
|
|
260
|
+
info: HashWithdrawRequestInfo;
|
|
261
|
+
};
|
|
262
|
+
type AddressScanOptions = {
|
|
263
|
+
gapLimit?: number;
|
|
264
|
+
startIndex?: number;
|
|
265
|
+
onFound?: (result: AddressScanResult) => void;
|
|
266
|
+
rateLimitBackoffMs?: number;
|
|
267
|
+
};
|
|
268
|
+
declare const scanForAddressNotes: (withdrawUrl: string, branch: Cx1, opts?: AddressScanOptions) => Promise<AddressScanResult[]>;
|
|
269
|
+
|
|
270
|
+
type SecretProvider = (domain: string) => string;
|
|
271
|
+
declare const configureSecretProvider: (provider: SecretProvider) => void;
|
|
272
|
+
type PubkeySecretProvider = (domain: string) => string | null;
|
|
273
|
+
declare const configurePubkeySecretProvider: (provider: PubkeySecretProvider) => void;
|
|
274
|
+
|
|
275
|
+
export { type AddressProofAction, type AddressScanOptions, type AddressScanResult, AmbiguousMintError, AmbiguousMutationError, type BoundMintCommitment, type Cx1, type HashWithdrawRequestInfo, type HashedMutationResult, type HashedSplitResult, type InternalTransferHint, type InternalTransferResult, type InvoiceResult, MINT_PUBKEY_PATTERN, MIN_COMMENT_LENGTH_FOR_SECRET, type MeltResult, type MintAddressInfo, type MintFee, NOTE_SIGNATURE_PATTERN, type NetworkGuard, NoteSpentError, NoteUnknownError, type PayRequestCommentInfo, type PayRequestInfo, PendingNoteError, type PubkeySecretProvider, type RotateResult, type SecretProvider, ServiceError, type SettledNote, type SplitResult, type Transport, type VerifyResult, type WithdrawRequestInfo, type WithdrawSuccessResponse, applyMintFee, buildNoteUrl, canUseMintComment, classifyNoteError, configureNetworkGuard, configurePubkeySecretProvider, configureSecretProvider, configureTransport, cp1FromCk1, decodeAnyCs1, decodeBolt11AmountMsat, decodeBolt11AmountSuffix, decodeBolt11PaymentHash, decodeCk1, decodeCp1, decodeCs1, decodeCs1WithAmount, decodeCx1, defaultSchemeFor, deriveNotePubkey, deriveNoteSecretKey, disclosedValue, encodeBolt11AmountSuffix, encodeCk1, encodeCp1, encodeCs1, encodeCs1WithAmount, encodeCx1, fetchInvoiceVerification, fetchMintAddress, fetchNoteInfo, fetchNoteInfoByHash, fetchNoteInfoByPubkey, fetchPayRequest, fromBech32Lnurl, fromLud17, generateOutputSecret, grossUpForMintFee, hashK1, isAllowedServiceUrl, isAnyCs1, isBech32Lnurl, isBolt11Invoice, isCk1, isCp1, isCs1, isCs1WithAmount, isCx1, isLightningAddress, isPreimage, isValidK1, isValidNoteInput, lightningAddressUsername, lnurlFetch, meltNote, mergeNotes, mergeNotesWithHash, mintAddressUrl, noteDeclaredAmount, noteEndpointOf, noteK1, noteSignature, parseInternalTransferHint, parseMintFee, parseMintKey, payInternalTransfer, probeBurnedNote, recoverNoteOwnershipPubkey, registerUsername, requestInvoice, requireBoundMintQuote, requireMintComment, requireMutationSignature, requireNoteK1, resolveLnurlInput, resolveMintInput, resolveNoteInput, rotateNote, rotateNoteWithHash, sameInvoice, scanForAddressNotes, serverOf, serviceOriginOf, settleNote, signAddressProof, signNoteOwnership, splitNote, splitNoteWithHash, toBech32Lnurl, toLud17w, unregisterUsername, validateBoundMintReceipt, verifyMeltPreimage, verifyNoteSignature, verifyNoteSignatureHash, withNewK1, withinMintFeeBand, withoutK1, withoutSignature };
|