@qntx/spark 0.0.0-stage → 0.1.1
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/LICENSE +201 -0
- package/NOTICE +6 -0
- package/README.md +59 -2
- package/dist/bolt11-DsNTTS_O.d.mts +52 -0
- package/dist/crypto.d.mts +3 -0
- package/dist/crypto.mjs +9 -0
- package/dist/errors-5xLkExNL.mjs +67 -0
- package/dist/index-B_g3vHnT.d.mts +820 -0
- package/dist/index-D1fBaHTa.d.mts +55 -0
- package/dist/index-DUSx3L3J.d.mts +69 -0
- package/dist/index.d.mts +115 -0
- package/dist/index.mjs +7322 -0
- package/dist/lightning-address-CRULmi9v.d.mts +106 -0
- package/dist/lightning-address-CZrb8x4p.mjs +92 -0
- package/dist/lnurl-kcdXU75g.mjs +729 -0
- package/dist/lnurl.d.mts +258 -0
- package/dist/lnurl.mjs +1 -0
- package/dist/server.d.mts +158 -0
- package/dist/server.mjs +373 -0
- package/dist/signer.d.mts +72 -0
- package/dist/signer.mjs +1024 -0
- package/dist/text-DC_Vptn6.mjs +303 -0
- package/dist/token-DmojVTWi.mjs +2122 -0
- package/dist/types-jBCznYd6.d.mts +322 -0
- package/package.json +98 -4
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
//#region src/errors/index.d.ts
|
|
2
|
+
/** Base class of every error raised by this package. */
|
|
3
|
+
declare class SparkError extends Error {
|
|
4
|
+
constructor(message: string, options?: ErrorOptions);
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* A failure reported by a {@link SparkCrypto} backend. `code` is the C ABI error code (see
|
|
8
|
+
* `qntx_spark.h`); the message never carries input bytes.
|
|
9
|
+
*/
|
|
10
|
+
declare class SparkCryptoError extends SparkError {
|
|
11
|
+
readonly code: number;
|
|
12
|
+
constructor(code: number, options?: ErrorOptions);
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Malformed caller- or peer-supplied data: a Spark address, a BOLT-11 invoice, an encoding. The
|
|
16
|
+
* message names the offending field and rule; it never echoes the input, so no secret or invoice
|
|
17
|
+
* content leaks into logs through error messages.
|
|
18
|
+
*/
|
|
19
|
+
declare class SparkInputError extends SparkError {
|
|
20
|
+
constructor(message: string, options?: ErrorOptions);
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* A request to a signing operator or the SSP failed. `code` uses one vocabulary: the gRPC canonical
|
|
24
|
+
* snake_case names for operator errors ("unauthenticated", "unavailable", "invalid_argument",
|
|
25
|
+
* "deadline_exceeded", … — Connect's PascalCase enum names are mapped down), `http_<status>` for
|
|
26
|
+
* SSP HTTP failures, `unexpected_response` for malformed SSP responses, and the SSP's GraphQL
|
|
27
|
+
* `extensions.code` lowercased. `operator` is the FROST identifier of the operator that failed,
|
|
28
|
+
* when the failure came from an operator. The message carries the server's own message — never
|
|
29
|
+
* request bodies.
|
|
30
|
+
*/
|
|
31
|
+
declare class SparkRequestError extends SparkError {
|
|
32
|
+
readonly code?: string | undefined;
|
|
33
|
+
readonly operator?: string | undefined;
|
|
34
|
+
constructor(message: string, options?: ErrorOptions & {
|
|
35
|
+
readonly code?: string;
|
|
36
|
+
readonly operator?: string;
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* A token broadcast's outcome is uncertain: the transaction may have committed server-side.
|
|
41
|
+
* `inputOutputIds` names the spent outputs — the caller passes it back to `tokens.transfer` or
|
|
42
|
+
* `tokens.consolidate` with the same receiver and amount, and that retry either returns the
|
|
43
|
+
* committed transaction's hash or broadcasts exactly those inputs once. Retrying without it would
|
|
44
|
+
* select different outputs and pay twice.
|
|
45
|
+
*/
|
|
46
|
+
declare class SparkTokenBroadcastError extends SparkRequestError {
|
|
47
|
+
readonly inputOutputIds: ReadonlyArray<string>;
|
|
48
|
+
constructor(message: string, options: ErrorOptions & {
|
|
49
|
+
readonly code?: string;
|
|
50
|
+
readonly operator?: string;
|
|
51
|
+
readonly inputOutputIds: ReadonlyArray<string>;
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
//#endregion
|
|
55
|
+
export { SparkTokenBroadcastError as a, SparkRequestError as i, SparkError as n, SparkInputError as r, SparkCryptoError as t };
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
//#region src/crypto/index.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* C ABI version implemented by a {@link SparkCrypto} backend. Bumped only when `qntx_spark.h`
|
|
4
|
+
* changes incompatibly; the signer verifies it at construction.
|
|
5
|
+
*/
|
|
6
|
+
declare const SPARK_ABI_VERSION = 1;
|
|
7
|
+
/**
|
|
8
|
+
* Curve-intensive Spark cryptography behind a bytes-only boundary. A backend maps 1:1 onto the C
|
|
9
|
+
* ABI in `qntx_spark.h` (`@qntx/spark-wasm` wraps the wasm32 build, `@qntx/spark-native` the native
|
|
10
|
+
* HybridObject); every method returns raw bytes and reports failure as a `SparkCryptoError` whose
|
|
11
|
+
* `code` is the ABI error code.
|
|
12
|
+
*
|
|
13
|
+
* Error codes: `0` success; `1` length error; `2` invalid scalar; `3` invalid point; `4` protobuf
|
|
14
|
+
* decode failure; `5` argument out of range (threshold, share count, job count cap 256); `6` FROST
|
|
15
|
+
* failure (invalid share, missing commitment); `7` decryption authentication failure; `8` internal
|
|
16
|
+
* error.
|
|
17
|
+
*/
|
|
18
|
+
type SparkCrypto = {
|
|
19
|
+
readonly abiVersion: number;
|
|
20
|
+
/**
|
|
21
|
+
* FROST signing nonces and commitments.
|
|
22
|
+
*
|
|
23
|
+
* `hedge` is a 32-byte signer-private hedge secret; `random` is `n`×32 bytes. Returns `n`×130
|
|
24
|
+
* bytes: per item `hiding‖binding` nonces (64) followed by the compressed `hiding‖binding`
|
|
25
|
+
* commitments (66). Each item runs frost `SigningNonces::new(hedge,
|
|
26
|
+
* ChaCha20Rng::from_seed(random_i))`. The hedge makes weak entropy safe, but nonce uniqueness
|
|
27
|
+
* still requires a fresh seed every call — the same seed under the same hedge reproduces the same
|
|
28
|
+
* nonces. The signer's `NonceStore` additionally rejects reuse of a commitment.
|
|
29
|
+
*/
|
|
30
|
+
frostCommit: (hedge: Uint8Array, random: Uint8Array) => Uint8Array;
|
|
31
|
+
/**
|
|
32
|
+
* User-side FROST signature shares.
|
|
33
|
+
*
|
|
34
|
+
* `request` is a protobuf `ffi.FrostSignRequest`; returns `ffi.FrostSignResponse` — one 32-byte
|
|
35
|
+
* signature share per job, in job order. The backend signs the user role under the `SingleUser`
|
|
36
|
+
* scheme with `Identifier::derive("user")`; the user verifying share is computed from the secret
|
|
37
|
+
* key inside the backend and never accepted as input.
|
|
38
|
+
*/
|
|
39
|
+
frostSign: (request: Uint8Array) => Uint8Array;
|
|
40
|
+
/**
|
|
41
|
+
* FROST aggregate signatures.
|
|
42
|
+
*
|
|
43
|
+
* `request` is a protobuf `ffi.FrostAggregateRequest`; returns `ffi.FrostAggregateResponse` — one
|
|
44
|
+
* 64-byte signature per job, in job order. When an adaptor public key is present the final
|
|
45
|
+
* verification is skipped per branch, matching upstream.
|
|
46
|
+
*/
|
|
47
|
+
frostAggregate: (request: Uint8Array) => Uint8Array;
|
|
48
|
+
/**
|
|
49
|
+
* ECIES encryption, byte-compatible with `ecies` 0.2 defaults.
|
|
50
|
+
*
|
|
51
|
+
* `publicKey` is a 33- or 65-byte secp256k1 public key; `random` is 32 bytes. Returns
|
|
52
|
+
* `ephemeralPk(65)‖nonce(16)‖tag(16)‖ciphertext`: HKDF-SHA256 over `ephemeralPk‖sharedPoint`
|
|
53
|
+
* (both uncompressed) with AES-256-GCM and a 16-byte nonce; the ephemeral key and nonce are
|
|
54
|
+
* derived from `random`.
|
|
55
|
+
*/
|
|
56
|
+
eciesEncrypt: (publicKey: Uint8Array, plaintext: Uint8Array, random: Uint8Array) => Uint8Array;
|
|
57
|
+
/** Inverse of {@link eciesEncrypt}: 32-byte private key and ciphertext yield the plaintext. */
|
|
58
|
+
eciesDecrypt: (privateKey: Uint8Array, ciphertext: Uint8Array) => Uint8Array;
|
|
59
|
+
/**
|
|
60
|
+
* Feldman VSS secret splitting, matching upstream `vss.rs` (`vsss-rs`) with seeded ChaCha20
|
|
61
|
+
* replacing its randomness source.
|
|
62
|
+
*
|
|
63
|
+
* `secret` is 32 bytes, `threshold` t ≥ 2, `shares` n ≥ t and `random` is 32 bytes. Returns
|
|
64
|
+
* `t`×33 proof bytes followed by `n`×32 share bytes; share indexes run 1..n.
|
|
65
|
+
*/
|
|
66
|
+
splitSecretWithProofs: (secret: Uint8Array, threshold: number, shares: number, random: Uint8Array) => Uint8Array;
|
|
67
|
+
};
|
|
68
|
+
//#endregion
|
|
69
|
+
export { SparkCrypto as n, SPARK_ABI_VERSION as t };
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import { a as SparkTokenBroadcastError, i as SparkRequestError, n as SparkError, r as SparkInputError, t as SparkCryptoError } from "./index-D1fBaHTa.mjs";
|
|
2
|
+
import { a as sparkNetworkConfig, i as SparkOperatorConfig, n as SparkNetwork, r as SparkNetworkConfig } from "./lightning-address-CRULmi9v.mjs";
|
|
3
|
+
import { i as isExpired, n as Bolt11Network, r as decodeBolt11, t as Bolt11Invoice } from "./bolt11-DsNTTS_O.mjs";
|
|
4
|
+
import { A as CooperativeExitStatus, C as exitTransactions, D as CooperativeExitQuote, E as createMemorySparkStore, F as UnusedDepositAddress, I as SparkLeaf, L as SparkEvent, M as StaticDepositClaim, N as StaticDepositRefund, O as CooperativeExitResult, P as StaticDepositUtxo, S as ExitTransaction, T as SparkStore, _ as LightningSendStatus, a as createSparkClient, b as LightningInvoice, c as buildCpfpChild, d as SparkTokenBalance, f as SparkTokenOutput, g as LightningSendOutcome, h as LightningReceiveStatus, i as SparkInvoiceStatus, j as MIN_STATIC_REFUND_FEE_SATS, k as CooperativeExitSpeed, l as SparkTransfer, m as SparkWalletSettings, n as SparkClient, o as StaticDepositClaimResult, p as SparkTokenOutputStatus, r as SparkClientOptions, s as FundingInput, t as ClaimPendingResult, u as SparkTransferLeaf, v as LightningSendStatusRequest, w as SparkExitChain, x as WatchtowerExitedLeaf, y as LightningPayment } from "./index-B_g3vHnT.mjs";
|
|
5
|
+
import { g as SparkSigner } from "./types-jBCznYd6.mjs";
|
|
6
|
+
//#region src/core/invoice.d.ts
|
|
7
|
+
/** Payment carried by a Spark invoice: satoshis or BTKN tokens. */
|
|
8
|
+
type SparkPayment = {
|
|
9
|
+
readonly type: "sats";
|
|
10
|
+
readonly amount?: number | undefined;
|
|
11
|
+
} | {
|
|
12
|
+
readonly type: "tokens";
|
|
13
|
+
/** 32-byte token identifier. */
|
|
14
|
+
readonly tokenIdentifier?: Uint8Array | undefined;
|
|
15
|
+
/** Big-endian uint128, at most 16 bytes. */
|
|
16
|
+
readonly amount?: Uint8Array | undefined;
|
|
17
|
+
};
|
|
18
|
+
/** Plain-TypeScript mirror of `spark.SparkInvoiceFields`; version is currently always 1. */
|
|
19
|
+
type SparkInvoiceFields = {
|
|
20
|
+
readonly version: number;
|
|
21
|
+
/** UUID identifying the invoice (canonical lowercase form). */
|
|
22
|
+
readonly id: string;
|
|
23
|
+
readonly payment?: SparkPayment | undefined;
|
|
24
|
+
/** At most 120 UTF-8 bytes. */
|
|
25
|
+
readonly memo?: string | undefined;
|
|
26
|
+
/** 33-byte compressed secp256k1 public key. */
|
|
27
|
+
readonly senderPublicKey?: Uint8Array | undefined;
|
|
28
|
+
/** Unix milliseconds. */
|
|
29
|
+
readonly expiresAt?: number | undefined;
|
|
30
|
+
};
|
|
31
|
+
//#endregion
|
|
32
|
+
//#region src/core/address.d.ts
|
|
33
|
+
/**
|
|
34
|
+
* Plain-TypeScript mirror of `spark.SparkAddress`. `signature` is the 64-byte schnorr signature
|
|
35
|
+
* over the invoice fields; signing and verification are handled by the signer.
|
|
36
|
+
*/
|
|
37
|
+
type SparkAddress = {
|
|
38
|
+
readonly network: SparkNetwork;
|
|
39
|
+
readonly identityPublicKey: Uint8Array;
|
|
40
|
+
readonly invoice?: SparkInvoiceFields | undefined;
|
|
41
|
+
readonly signature?: Uint8Array | undefined;
|
|
42
|
+
};
|
|
43
|
+
/** Encodes a Spark address as `hrp1…` bech32m (the network's current prefix). */
|
|
44
|
+
export declare function encodeSparkAddress(address: SparkAddress): string;
|
|
45
|
+
/**
|
|
46
|
+
* Decodes a bech32m Spark address. Current (`spark`, `sparkrt`) and legacy (`sp`, `sprt`) prefixes
|
|
47
|
+
* are accepted; the prefix selects the network. Throws {@link SparkInputError} on malformed input.
|
|
48
|
+
*/
|
|
49
|
+
export declare function decodeSparkAddress(address: string): SparkAddress;
|
|
50
|
+
/**
|
|
51
|
+
* Verifies the BIP-340 schnorr signature a Spark invoice carries: the signature covers
|
|
52
|
+
* `hashSparkInvoice(invoice, identityPublicKey, network)` under the x-only identity public key.
|
|
53
|
+
* Returns false for a missing invoice/signature or an invalid signature, matching upstream
|
|
54
|
+
* `validateSparkInvoiceSignature`'s verification step.
|
|
55
|
+
*/
|
|
56
|
+
export declare function verifySparkAddressSignature(address: SparkAddress): boolean;
|
|
57
|
+
//#endregion
|
|
58
|
+
//#region src/core/token-identifier.d.ts
|
|
59
|
+
type SparkTokenIdentifierData = {
|
|
60
|
+
readonly tokenIdentifier: Uint8Array;
|
|
61
|
+
readonly network: SparkNetwork;
|
|
62
|
+
};
|
|
63
|
+
/** Encodes a raw 32-byte token identifier as `btkn1…`/`btknrt1…` bech32m. */
|
|
64
|
+
export declare function encodeTokenIdentifier(tokenIdentifier: Uint8Array, network: SparkNetwork): string;
|
|
65
|
+
/**
|
|
66
|
+
* Decodes a bech32m token identifier. Only the `btkn` (mainnet) and `btknrt` (regtest) prefixes are
|
|
67
|
+
* accepted; the prefix selects the network. Throws {@link SparkInputError} on malformed input.
|
|
68
|
+
*/
|
|
69
|
+
export declare function decodeTokenIdentifier(text: string): SparkTokenIdentifierData;
|
|
70
|
+
//#endregion
|
|
71
|
+
//#region src/invoice/create.d.ts
|
|
72
|
+
type InvoiceOptions = {
|
|
73
|
+
readonly signer: SparkSigner;
|
|
74
|
+
readonly network: SparkNetwork;
|
|
75
|
+
readonly random: (length: number) => Uint8Array;
|
|
76
|
+
readonly now: () => number;
|
|
77
|
+
readonly memo?: string;
|
|
78
|
+
/** Restricts payment to this sender identity public key. */
|
|
79
|
+
readonly senderPublicKey?: Uint8Array;
|
|
80
|
+
/** Unix milliseconds; the invoice is rejected once expired. */
|
|
81
|
+
readonly expiresAtMs?: number;
|
|
82
|
+
};
|
|
83
|
+
/**
|
|
84
|
+
* Builds a signed sats invoice address for this identity. `amountSats` may be omitted for an
|
|
85
|
+
* open-amount invoice the payer fills in.
|
|
86
|
+
*/
|
|
87
|
+
export declare function createSatsInvoice(options: InvoiceOptions & {
|
|
88
|
+
readonly amountSats?: number;
|
|
89
|
+
}): Promise<string>;
|
|
90
|
+
/**
|
|
91
|
+
* Builds a signed tokens invoice address for this identity. `tokenIdentifier` (32 bytes raw) and
|
|
92
|
+
* `amount` may be omitted; payers then pick the token and amount.
|
|
93
|
+
*/
|
|
94
|
+
export declare function createTokensInvoice(options: InvoiceOptions & {
|
|
95
|
+
readonly tokenIdentifier?: Uint8Array;
|
|
96
|
+
readonly amount?: bigint;
|
|
97
|
+
}): Promise<string>;
|
|
98
|
+
//#endregion
|
|
99
|
+
//#region src/invoice/parse.d.ts
|
|
100
|
+
type ParsedSparkInvoice = {
|
|
101
|
+
readonly receiverIdentityPublicKey: Uint8Array;
|
|
102
|
+
readonly fields: SparkInvoiceFields;
|
|
103
|
+
/** True when the invoice carries a signature that verifies under the receiver's key. */
|
|
104
|
+
readonly signed: boolean;
|
|
105
|
+
};
|
|
106
|
+
/**
|
|
107
|
+
* Decodes and validates a signed invoice address: must be an invoice-carrying Spark address for
|
|
108
|
+
* `network`, any signature must verify, and the invoice must not be expired at `now`.
|
|
109
|
+
*/
|
|
110
|
+
export declare function parseSparkInvoice(text: string, options: {
|
|
111
|
+
readonly network: SparkNetwork;
|
|
112
|
+
readonly now: number;
|
|
113
|
+
}): ParsedSparkInvoice;
|
|
114
|
+
//#endregion
|
|
115
|
+
export { type Bolt11Invoice, type Bolt11Network, type ClaimPendingResult, type CooperativeExitQuote, type CooperativeExitResult, type CooperativeExitSpeed, type CooperativeExitStatus, type ExitTransaction, type FundingInput, type LightningInvoice, type LightningPayment, type LightningReceiveStatus, type LightningSendOutcome, type LightningSendStatus, type LightningSendStatusRequest, MIN_STATIC_REFUND_FEE_SATS, type ParsedSparkInvoice, type SparkAddress, type SparkClient, type SparkClientOptions, SparkCryptoError, SparkError, type SparkEvent, type SparkExitChain, SparkInputError, type SparkInvoiceFields, type SparkInvoiceStatus, type SparkLeaf, type SparkNetwork, type SparkNetworkConfig, type SparkOperatorConfig, type SparkPayment, SparkRequestError, type SparkStore, type SparkTokenBalance, SparkTokenBroadcastError, type SparkTokenIdentifierData, type SparkTokenOutput, type SparkTokenOutputStatus, type SparkTransfer, type SparkTransferLeaf, type SparkWalletSettings, type StaticDepositClaim, type StaticDepositClaimResult, type StaticDepositRefund, type StaticDepositUtxo, type UnusedDepositAddress, type WatchtowerExitedLeaf, buildCpfpChild, createMemorySparkStore, createSparkClient, decodeBolt11, exitTransactions, isExpired, sparkNetworkConfig };
|