@ghostlytools/sdk 0.0.0-stage → 1.2.4
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/README.md +13 -2
- package/dist/app.js +72 -0
- package/dist/app.js.map +1 -0
- package/dist/core.js +207 -0
- package/dist/core.js.map +1 -0
- package/dist/fakes-JOzOFxn3.js +536 -0
- package/dist/fakes-JOzOFxn3.js.map +1 -0
- package/dist/fakes.js +2 -0
- package/dist/index.js +179 -0
- package/dist/index.js.map +1 -0
- package/dist/keet-identity-key-BLli1rE4.js +76483 -0
- package/dist/keet-identity-key-BLli1rE4.js.map +1 -0
- package/dist/src-BqHTnRWH.js +31296 -0
- package/dist/src-BqHTnRWH.js.map +1 -0
- package/dist/testing.js +330 -0
- package/dist/testing.js.map +1 -0
- package/dist/types/browser/src/engine/paymentAdapters/providers/contractSuite.d.ts +41 -0
- package/dist/types/browser/src/engine/paymentAdapters/providers/lightning.d.ts +103 -0
- package/dist/types/browser/src/engine/paymentAdapters/providers/onchain.d.ts +88 -0
- package/dist/types/browser/src/engine/paymentAdapters/providers/testing.d.ts +89 -0
- package/dist/types/browser/src/engine/paymentAdapters/providers/types.d.ts +151 -0
- package/dist/types/browser/src/plugins/bundled.d.ts +8 -0
- package/dist/types/browser/src/plugins/registry.d.ts +57 -0
- package/dist/types/browser/src/proofs/contract.d.ts +262 -0
- package/dist/types/browser/src/proofs/contractSuite.d.ts +27 -0
- package/dist/types/browser/src/proofs/testing.d.ts +36 -0
- package/dist/types/browser/src/proofs/verify.d.ts +23 -0
- package/dist/types/browser/src/shared/mints.d.ts +50 -0
- package/dist/types/core/src/appBundle.d.ts +173 -0
- package/dist/types/core/src/appStatements.d.ts +142 -0
- package/dist/types/core/src/appStore.d.ts +133 -0
- package/dist/types/core/src/appUpdates.d.ts +88 -0
- package/dist/types/core/src/atprotoIdentity.d.ts +49 -0
- package/dist/types/core/src/atprotoRepo.d.ts +101 -0
- package/dist/types/core/src/avatar.d.ts +19 -0
- package/dist/types/core/src/bip322.d.ts +57 -0
- package/dist/types/core/src/bitcoinAddress.d.ts +5 -0
- package/dist/types/core/src/bitcoinMessage.d.ts +15 -0
- package/dist/types/core/src/bitcoinScript.d.ts +69 -0
- package/dist/types/core/src/bolt11.d.ts +30 -0
- package/dist/types/core/src/bytes.d.ts +11 -0
- package/dist/types/core/src/callSignal.d.ts +232 -0
- package/dist/types/core/src/canonicalJson.d.ts +22 -0
- package/dist/types/core/src/capsRecord.d.ts +234 -0
- package/dist/types/core/src/catchUp.d.ts +45 -0
- package/dist/types/core/src/chatFiles.d.ts +271 -0
- package/dist/types/core/src/clockWatch.d.ts +72 -0
- package/dist/types/core/src/communityRendezvous.d.ts +113 -0
- package/dist/types/core/src/crypto.d.ts +10 -0
- package/dist/types/core/src/datalink.d.ts +187 -0
- package/dist/types/core/src/deviceInvite.d.ts +51 -0
- package/dist/types/core/src/deviceLink.d.ts +70 -0
- package/dist/types/core/src/dhtDelivery.d.ts +407 -0
- package/dist/types/core/src/dhtFiles.d.ts +46 -0
- package/dist/types/core/src/did.d.ts +134 -0
- package/dist/types/core/src/didDht.d.ts +155 -0
- package/dist/types/core/src/directPath.d.ts +63 -0
- package/dist/types/core/src/dns.d.ts +41 -0
- package/dist/types/core/src/domainProofs.d.ts +88 -0
- package/dist/types/core/src/engineErrors.d.ts +91 -0
- package/dist/types/core/src/enroll.d.ts +98 -0
- package/dist/types/core/src/files.d.ts +73 -0
- package/dist/types/core/src/forwards.d.ts +12 -0
- package/dist/types/core/src/frames.d.ts +211 -0
- package/dist/types/core/src/ghostlink.d.ts +1532 -0
- package/dist/types/core/src/groupCommits.d.ts +103 -0
- package/dist/types/core/src/groupCommunity.d.ts +720 -0
- package/dist/types/core/src/groupCrypto.d.ts +60 -0
- package/dist/types/core/src/groupEdits.d.ts +67 -0
- package/dist/types/core/src/groupEntry.d.ts +61 -0
- package/dist/types/core/src/groupFiles.d.ts +106 -0
- package/dist/types/core/src/groupHubs.d.ts +61 -0
- package/dist/types/core/src/groupMentions.d.ts +27 -0
- package/dist/types/core/src/groupMeta.d.ts +162 -0
- package/dist/types/core/src/groupSession.d.ts +728 -0
- package/dist/types/core/src/groupSignals.d.ts +167 -0
- package/dist/types/core/src/groupTyping.d.ts +56 -0
- package/dist/types/core/src/groupWake.d.ts +68 -0
- package/dist/types/core/src/handoff.d.ts +255 -0
- package/dist/types/core/src/http.d.ts +125 -0
- package/dist/types/core/src/identity.d.ts +17 -0
- package/dist/types/core/src/identityProofs.d.ts +243 -0
- package/dist/types/core/src/identityTimeline.d.ts +72 -0
- package/dist/types/core/src/image.d.ts +33 -0
- package/dist/types/core/src/index.d.ts +100 -0
- package/dist/types/core/src/invite.d.ts +128 -0
- package/dist/types/core/src/link.d.ts +353 -0
- package/dist/types/core/src/linkPreview.d.ts +60 -0
- package/dist/types/core/src/linkTrace.d.ts +12 -0
- package/dist/types/core/src/lnurl.d.ts +99 -0
- package/dist/types/core/src/messageTime.d.ts +28 -0
- package/dist/types/core/src/miniApp.d.ts +146 -0
- package/dist/types/core/src/pairedApps.d.ts +151 -0
- package/dist/types/core/src/pairedCalls.d.ts +59 -0
- package/dist/types/core/src/pairedCapabilities.d.ts +101 -0
- package/dist/types/core/src/pairedEdits.d.ts +83 -0
- package/dist/types/core/src/pairedFiles.d.ts +30 -0
- package/dist/types/core/src/pairedHttp.d.ts +15 -0
- package/dist/types/core/src/pairedSession.d.ts +163 -0
- package/dist/types/core/src/pairedSignal.d.ts +17 -0
- package/dist/types/core/src/pairedTransports.d.ts +76 -0
- package/dist/types/core/src/pairedTyping.d.ts +130 -0
- package/dist/types/core/src/pairedWake.d.ts +109 -0
- package/dist/types/core/src/pairingProgress.d.ts +107 -0
- package/dist/types/core/src/paymentIntent.d.ts +111 -0
- package/dist/types/core/src/paymentUri.d.ts +34 -0
- package/dist/types/core/src/payments.d.ts +97 -0
- package/dist/types/core/src/peerProofs.d.ts +98 -0
- package/dist/types/core/src/pins.d.ts +73 -0
- package/dist/types/core/src/pkarr.d.ts +48 -0
- package/dist/types/core/src/pkdns.d.ts +35 -0
- package/dist/types/core/src/pubkyProofs.d.ts +25 -0
- package/dist/types/core/src/pubkyRing.d.ts +21 -0
- package/dist/types/core/src/reactions.d.ts +108 -0
- package/dist/types/core/src/records.d.ts +89 -0
- package/dist/types/core/src/relay.d.ts +459 -0
- package/dist/types/core/src/relayBreaker.d.ts +99 -0
- package/dist/types/core/src/replies.d.ts +41 -0
- package/dist/types/core/src/services.d.ts +35 -0
- package/dist/types/core/src/setUpdate.d.ts +53 -0
- package/dist/types/core/src/signal.d.ts +53 -0
- package/dist/types/core/src/signer.d.ts +13 -0
- package/dist/types/core/src/sparkAddress.d.ts +37 -0
- package/dist/types/core/src/sshsig.d.ts +74 -0
- package/dist/types/core/src/statusCards.d.ts +253 -0
- package/dist/types/core/src/storeForward.d.ts +144 -0
- package/dist/types/core/src/text.d.ts +20 -0
- package/dist/types/core/src/transport.d.ts +158 -0
- package/dist/types/core/src/transportSwitch.d.ts +160 -0
- package/dist/types/core/src/turnRead.d.ts +145 -0
- package/dist/types/core/src/turnRecord.d.ts +165 -0
- package/dist/types/core/src/version.d.ts +9 -0
- package/dist/types/core/src/video.d.ts +44 -0
- package/dist/types/core/src/voice.d.ts +88 -0
- package/dist/types/core/src/webPush.d.ts +58 -0
- package/dist/types/sdk/src/app.d.ts +23 -0
- package/dist/types/sdk/src/core.d.ts +7 -0
- package/dist/types/sdk/src/fakes.d.ts +6 -0
- package/dist/types/sdk/src/index.d.ts +26 -0
- package/dist/types/sdk/src/testing.d.ts +7 -0
- package/dist/types-DvtCy3WB.js +99 -0
- package/dist/types-DvtCy3WB.js.map +1 -0
- package/dist/verify-RjMx7eW6.js +106 -0
- package/dist/verify-RjMx7eW6.js.map +1 -0
- package/package.json +70 -4
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Checking one record of an AT Protocol repository without trusting the server that serves it: the
|
|
3
|
+
* CAR file `com.atproto.sync.getRecord` returns holds the signed commit, the Merkle Search Tree nodes
|
|
4
|
+
* from the commit's root down to the record, and the record itself. Every block is checked against its
|
|
5
|
+
* hash, the commit's signature against the DID's signing key, and the path through the tree to the key
|
|
6
|
+
* `collection/rkey`. Only what atproto's data model uses is accepted (DAG-CBOR without floats or
|
|
7
|
+
* undefined, CIDv1 with SHA-256), strictly: canonical lengths and map order, so re-encoding the unsigned
|
|
8
|
+
* commit gives exactly the bytes that were signed.
|
|
9
|
+
*
|
|
10
|
+
* Specs: https://atproto.com/specs/repository, https://atproto.com/specs/data-model,
|
|
11
|
+
* https://atproto.com/specs/cryptography. No network here: the caller fetches, bounded.
|
|
12
|
+
*/
|
|
13
|
+
export declare class AtprotoProofError extends Error {
|
|
14
|
+
}
|
|
15
|
+
/** A CIDv1 as atproto uses it: dag-cbor or raw, SHA-256. */
|
|
16
|
+
export declare class AtprotoCid {
|
|
17
|
+
readonly bytes: Uint8Array;
|
|
18
|
+
readonly codec: number;
|
|
19
|
+
readonly digest: Uint8Array;
|
|
20
|
+
constructor(bytes: Uint8Array, codec: number, digest: Uint8Array);
|
|
21
|
+
/** Stable key for maps: the CID's bytes in hex. */
|
|
22
|
+
get key(): string;
|
|
23
|
+
equals(other: AtprotoCid): boolean;
|
|
24
|
+
}
|
|
25
|
+
/** A binary CID at `offset`; returns it and where it ends. */
|
|
26
|
+
export declare function readAtprotoCid(bytes: Uint8Array, offset?: number): [AtprotoCid, number];
|
|
27
|
+
/** The CID of `data` under `codec` (dag-cbor by default). */
|
|
28
|
+
export declare function atprotoCidFor(data: Uint8Array, codec?: number): AtprotoCid;
|
|
29
|
+
/** A decoded DAG-CBOR value. Maps are null-prototype objects, links are `AtprotoCid`. */
|
|
30
|
+
export type CborValue = null | boolean | number | string | Uint8Array | AtprotoCid | CborValue[] | {
|
|
31
|
+
[key: string]: CborValue;
|
|
32
|
+
};
|
|
33
|
+
/** Decodes exactly one DAG-CBOR value filling all of `bytes`. */
|
|
34
|
+
export declare function decodeDagCbor(bytes: Uint8Array): CborValue;
|
|
35
|
+
/** Encodes a value as DAG-CBOR (canonical: minimal lengths, sorted keys). */
|
|
36
|
+
export declare function encodeDagCbor(value: CborValue): Uint8Array;
|
|
37
|
+
export interface AtprotoCar {
|
|
38
|
+
roots: AtprotoCid[];
|
|
39
|
+
blocks: Map<string, {
|
|
40
|
+
cid: AtprotoCid;
|
|
41
|
+
data: Uint8Array;
|
|
42
|
+
}>;
|
|
43
|
+
}
|
|
44
|
+
/** Parses a CARv1 file and checks every block against its CID. */
|
|
45
|
+
export declare function parseAtprotoCar(bytes: Uint8Array, { maxBlocks }?: {
|
|
46
|
+
maxBlocks?: number;
|
|
47
|
+
}): AtprotoCar;
|
|
48
|
+
export type AtprotoKeyType = "secp256k1" | "p256";
|
|
49
|
+
export interface AtprotoPublicKey {
|
|
50
|
+
type: AtprotoKeyType; /** Compressed SEC1 point (33 bytes). */
|
|
51
|
+
key: Uint8Array;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* The atproto signing key of a DID document's verification method: `Multikey` (multicodec-prefixed,
|
|
55
|
+
* compressed) or the legacy `EcdsaSecp256k1VerificationKey2019` / `EcdsaSecp256r1VerificationKey2019`
|
|
56
|
+
* (the bare point). Both are base58btc multibase ("z…").
|
|
57
|
+
*/
|
|
58
|
+
export declare function parseAtprotoVerificationKey(type: string, publicKeyMultibase: string): AtprotoPublicKey;
|
|
59
|
+
/** A `did:key:z…` (atproto's form, multicodec-prefixed compressed key). */
|
|
60
|
+
export declare function parseAtprotoDidKey(didKey: string): AtprotoPublicKey;
|
|
61
|
+
/** atproto signatures: ECDSA over SHA-256 of the bytes, 64-byte compact r‖s, low-S only. */
|
|
62
|
+
export declare function verifyAtprotoSignature(key: AtprotoPublicKey, data: Uint8Array, sig: Uint8Array): boolean;
|
|
63
|
+
export interface AtprotoCommit {
|
|
64
|
+
did: string;
|
|
65
|
+
version: 3;
|
|
66
|
+
data: AtprotoCid;
|
|
67
|
+
rev: string;
|
|
68
|
+
prev: AtprotoCid | null;
|
|
69
|
+
sig: Uint8Array;
|
|
70
|
+
}
|
|
71
|
+
export declare function decodeAtprotoCommit(data: Uint8Array): AtprotoCommit;
|
|
72
|
+
/** The bytes a commit's signature covers: the commit without `sig`, re-encoded. */
|
|
73
|
+
export declare function unsignedCommitBytes(data: Uint8Array): Uint8Array;
|
|
74
|
+
/**
|
|
75
|
+
* Walks the tree from `root` to `key`. Returns the value's CID, or null when the blocks prove the key is
|
|
76
|
+
* absent. Throws when a block on the path is missing: the CAR proves neither.
|
|
77
|
+
*/
|
|
78
|
+
export declare function findInMst(blocks: AtprotoCar["blocks"], root: AtprotoCid, key: string, { maxDepth }?: {
|
|
79
|
+
maxDepth?: number;
|
|
80
|
+
}): AtprotoCid | null;
|
|
81
|
+
/** What a verified record proof says. */
|
|
82
|
+
export interface AtprotoRecordProof {
|
|
83
|
+
commit: AtprotoCommit;
|
|
84
|
+
/** The record's CID and its decoded value, or null when the repository proves it absent. */
|
|
85
|
+
record: {
|
|
86
|
+
cid: AtprotoCid;
|
|
87
|
+
value: {
|
|
88
|
+
[key: string]: CborValue;
|
|
89
|
+
};
|
|
90
|
+
} | null;
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Verifies a `com.atproto.sync.getRecord` CAR for `did`'s `collection/rkey`, signed by `key` (from the DID
|
|
94
|
+
* document, never from the CAR or the server). Throws AtprotoProofError on any mismatch.
|
|
95
|
+
*/
|
|
96
|
+
export declare function verifyAtprotoRecordProof(car: Uint8Array, options: {
|
|
97
|
+
did: string;
|
|
98
|
+
key: AtprotoPublicKey;
|
|
99
|
+
collection: string;
|
|
100
|
+
rkey: string;
|
|
101
|
+
}): AtprotoRecordProof;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A profile picture as it travels between paired peers: a small square JPEG in a data URL. The picture
|
|
3
|
+
* a contact sends is shown next to their chats, so it is checked here before anything draws it: the
|
|
4
|
+
* format, the size, and the dimensions its header declares (a tiny file can claim a huge image).
|
|
5
|
+
*/
|
|
6
|
+
/** Longest data URL kept: a 128×128 JPEG is a few KB; this leaves room and no more. */
|
|
7
|
+
export declare const MAX_AVATAR_LENGTH = 48000;
|
|
8
|
+
/** Largest side a picture may declare. What Ghostly sends is 128. */
|
|
9
|
+
export declare const MAX_AVATAR_SIDE = 512;
|
|
10
|
+
/** Width and height from a JPEG's frame header, or undefined when there is none before the image data. */
|
|
11
|
+
export declare function jpegSize(bytes: Uint8Array): {
|
|
12
|
+
width: number;
|
|
13
|
+
height: number;
|
|
14
|
+
} | undefined;
|
|
15
|
+
/**
|
|
16
|
+
* The picture if it is one Ghostly will show, `null` for "no picture" (an empty string), and undefined
|
|
17
|
+
* for anything else, which is ignored.
|
|
18
|
+
*/
|
|
19
|
+
export declare function sanitizeAvatar(value: unknown): string | null | undefined;
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { type BitcoinAddressInfo, type Tx } from "./bitcoinScript.js";
|
|
2
|
+
/**
|
|
3
|
+
* BIP-322 "Generic Signed Message Format", verification only, pinned to **version 2.0.0** of the BIP
|
|
4
|
+
* (bitcoin/bips commit 4061a54418f62a5a1ae44f4604e56373329bfad3, 2026-06-05), whose official test vectors
|
|
5
|
+
* are in packages/core/test/fixtures/bip322/.
|
|
6
|
+
*
|
|
7
|
+
* Without a full script interpreter, this verifier checks the scripts it understands and says
|
|
8
|
+
* "inconclusive" for the rest, as the BIP allows:
|
|
9
|
+
*
|
|
10
|
+
* - P2WPKH (bc1q…, 42 chars) simple and full
|
|
11
|
+
* - P2TR (bc1p…) key path simple and full
|
|
12
|
+
* - P2SH-P2WPKH (3…) full only: the simple format is for native SegWit
|
|
13
|
+
* - P2PKH (1…) full only
|
|
14
|
+
*
|
|
15
|
+
* Multisig and other scripts (P2WSH, bare P2SH, Taproot script path) and proofs of funds (`pof`) are
|
|
16
|
+
* inconclusive, which a proof treats as not proven.
|
|
17
|
+
*/
|
|
18
|
+
export declare const BIP322_REVISION = "2.0.0 (bitcoin/bips@4061a54418f62a5a1ae44f4604e56373329bfad3)";
|
|
19
|
+
export type Bip322Format = "bip322-simple" | "bip322-full";
|
|
20
|
+
export type BitcoinProofScript = "p2pkh" | "p2wpkh" | "p2sh-p2wpkh" | "p2tr";
|
|
21
|
+
export interface Bip322Valid {
|
|
22
|
+
format: Bip322Format;
|
|
23
|
+
script: BitcoinProofScript;
|
|
24
|
+
/** The full format's nLockTime and first nSequence, when the signer set them (BIP-322: "valid at time T and age S"). */
|
|
25
|
+
lockTime?: number;
|
|
26
|
+
sequence?: number;
|
|
27
|
+
}
|
|
28
|
+
export type BitcoinMessageVerdict = ({
|
|
29
|
+
state: "valid";
|
|
30
|
+
} & (Bip322Valid | {
|
|
31
|
+
format: "legacy";
|
|
32
|
+
script: "p2pkh";
|
|
33
|
+
}))
|
|
34
|
+
/** Something checked failed: wrong key, message, address or a malformed signature. */
|
|
35
|
+
| {
|
|
36
|
+
state: "invalid";
|
|
37
|
+
reason: string;
|
|
38
|
+
}
|
|
39
|
+
/** Maybe valid, but not something this verifier can check (a multisig, a time lock…). Never treat as proven. */
|
|
40
|
+
| {
|
|
41
|
+
state: "inconclusive";
|
|
42
|
+
reason: string;
|
|
43
|
+
};
|
|
44
|
+
/** A refusal while verifying; `inconclusive` for what cannot be checked rather than what failed. */
|
|
45
|
+
export declare class MessageRefusal extends Error {
|
|
46
|
+
readonly state: "invalid" | "inconclusive";
|
|
47
|
+
constructor(state: "invalid" | "inconclusive", reason: string);
|
|
48
|
+
}
|
|
49
|
+
export declare const bip322MessageHash: (message: string) => Uint8Array<ArrayBufferLike> & Uint8Array<ArrayBuffer>;
|
|
50
|
+
/** The virtual transaction whose only output pays the address; `to_sign` spends it. */
|
|
51
|
+
export declare function bip322ToSpend(message: string, scriptPubKey: Uint8Array): Tx;
|
|
52
|
+
/** `to_sign` with every field at the default the simple format assumes. */
|
|
53
|
+
export declare function bip322ToSign(toSpend: Tx, witness?: Uint8Array[]): Tx;
|
|
54
|
+
/** Standard base64, whitespace (a pasted line break) ignored; missing padding tolerated. */
|
|
55
|
+
export declare function decodeBase64(text: string): Uint8Array;
|
|
56
|
+
/** Checks a BIP-322 signature — `smp…`, `ful…`, or an unprefixed one read as simple — or throws a `MessageRefusal`. */
|
|
57
|
+
export declare function verifyBip322(address: BitcoinAddressInfo, message: string, signature: string): Bip322Valid;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
/** The Bitcoin networks an on-chain wallet can be on. Only `bitcoin` is real money. */
|
|
2
|
+
export type BitcoinNetwork = "bitcoin" | "signet" | "testnet" | "regtest" | "mutinynet";
|
|
3
|
+
export declare const BITCOIN_NETWORKS: readonly BitcoinNetwork[];
|
|
4
|
+
/** Whether `address` is a valid address on `network`: checksums, witness versions, lengths and prefixes. */
|
|
5
|
+
export declare function isBitcoinAddress(address: unknown, network: BitcoinNetwork): boolean;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { type BitcoinMessageVerdict } from "./bip322.js";
|
|
2
|
+
import { type BitcoinProofNetwork } from "./bitcoinScript.js";
|
|
3
|
+
/** The digest `signmessage` signs: double SHA-256 of the length-prefixed magic and message. */
|
|
4
|
+
export declare function legacyMessageHash(message: string): Uint8Array;
|
|
5
|
+
/** Header bytes 27-34 are P2PKH (uncompressed 27-30, compressed 31-34); 35-42 are BIP 137 SegWit headers. */
|
|
6
|
+
export declare const isLegacySignature: (bytes: Uint8Array) => boolean;
|
|
7
|
+
export interface BitcoinMessageInput {
|
|
8
|
+
address: string;
|
|
9
|
+
message: string;
|
|
10
|
+
signature: string;
|
|
11
|
+
/** Mainnet accepts only real-network addresses; Testnet any test network's (testnet, signet, regtest). */
|
|
12
|
+
network: BitcoinProofNetwork;
|
|
13
|
+
}
|
|
14
|
+
/** Never throws: every refusal comes back as `invalid` or `inconclusive` with a reason fit to show. */
|
|
15
|
+
export declare function verifyBitcoinMessage({ address, message, signature, network }: BitcoinMessageInput): BitcoinMessageVerdict;
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The little of Bitcoin's address and transaction formats a message-signature verifier needs: decoding an
|
|
3
|
+
* address to its output script, and (de)serialising the two virtual transactions of BIP-322. Nothing here
|
|
4
|
+
* builds, signs or broadcasts a real transaction.
|
|
5
|
+
*/
|
|
6
|
+
/** Which addresses a proof may name: the real network, or any of the test networks (testnet, signet, regtest…). */
|
|
7
|
+
export type BitcoinProofNetwork = "mainnet" | "testnet";
|
|
8
|
+
export type BitcoinScriptType = "p2pkh" | "p2sh" | "p2wpkh" | "p2wsh" | "p2tr" | "witness-unknown";
|
|
9
|
+
export interface BitcoinAddressInfo {
|
|
10
|
+
address: string;
|
|
11
|
+
type: BitcoinScriptType;
|
|
12
|
+
network: BitcoinProofNetwork;
|
|
13
|
+
/** The output script paying this address. */
|
|
14
|
+
scriptPubKey: Uint8Array;
|
|
15
|
+
/** The key/script hash of a base58 address, or the witness program of a SegWit one. */
|
|
16
|
+
program: Uint8Array;
|
|
17
|
+
witnessVersion?: number;
|
|
18
|
+
}
|
|
19
|
+
export declare const sha256d: (...parts: Uint8Array[]) => Uint8Array<ArrayBufferLike> & Uint8Array<ArrayBuffer>;
|
|
20
|
+
export declare const hash160: (data: Uint8Array) => Uint8Array<ArrayBufferLike> & Uint8Array<ArrayBuffer>;
|
|
21
|
+
/** An address refused, with a reason fit to show the person. */
|
|
22
|
+
export declare class BitcoinAddressError extends Error {
|
|
23
|
+
}
|
|
24
|
+
/** Decodes `address` for `network`, or throws a `BitcoinAddressError` saying what is wrong with it. */
|
|
25
|
+
export declare function decodeBitcoinAddress(address: string, network: BitcoinProofNetwork): BitcoinAddressInfo;
|
|
26
|
+
export interface TxInput {
|
|
27
|
+
txid: Uint8Array;
|
|
28
|
+
vout: number;
|
|
29
|
+
scriptSig: Uint8Array;
|
|
30
|
+
sequence: number;
|
|
31
|
+
witness: Uint8Array[];
|
|
32
|
+
}
|
|
33
|
+
export interface TxOutput {
|
|
34
|
+
value: bigint;
|
|
35
|
+
script: Uint8Array;
|
|
36
|
+
}
|
|
37
|
+
export interface Tx {
|
|
38
|
+
version: number;
|
|
39
|
+
inputs: TxInput[];
|
|
40
|
+
outputs: TxOutput[];
|
|
41
|
+
lockTime: number;
|
|
42
|
+
}
|
|
43
|
+
export declare function compactSize(n: number): Uint8Array;
|
|
44
|
+
export declare const varBytes: (b: Uint8Array) => Uint8Array<ArrayBufferLike>;
|
|
45
|
+
export declare const u32: (n: number) => Uint8Array<ArrayBuffer>;
|
|
46
|
+
export declare const u64: (n: bigint) => Uint8Array<ArrayBuffer>;
|
|
47
|
+
export declare function encodeTx(tx: Tx, withWitness?: boolean): Uint8Array;
|
|
48
|
+
export declare const encodeWitness: (stack: Uint8Array[]) => Uint8Array<ArrayBufferLike>;
|
|
49
|
+
/** The id other transactions refer to it by, in internal byte order (reverse it for display). */
|
|
50
|
+
export declare const txHash: (tx: Tx) => Uint8Array<ArrayBufferLike> & Uint8Array<ArrayBuffer>;
|
|
51
|
+
/** A strict reader: canonical sizes only, and the whole input must be consumed. */
|
|
52
|
+
export declare class ByteReader {
|
|
53
|
+
private bytes;
|
|
54
|
+
private at;
|
|
55
|
+
constructor(bytes: Uint8Array);
|
|
56
|
+
get done(): boolean;
|
|
57
|
+
take(n: number): Uint8Array;
|
|
58
|
+
peek(): number;
|
|
59
|
+
u32(): number;
|
|
60
|
+
i32(): number;
|
|
61
|
+
u64(): bigint;
|
|
62
|
+
compactSize(): number;
|
|
63
|
+
varBytes(): Uint8Array;
|
|
64
|
+
end(): void;
|
|
65
|
+
}
|
|
66
|
+
export declare function decodeWitness(bytes: Uint8Array): Uint8Array[];
|
|
67
|
+
export declare function decodeTx(bytes: Uint8Array): Tx;
|
|
68
|
+
/** The address decoded on whichever network it belongs to (mainnet first), or a `BitcoinAddressError`. */
|
|
69
|
+
export declare function decodeAnyBitcoinAddress(address: string): BitcoinAddressInfo;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Reads what a Lightning invoice (BOLT11) asks for, so a pasted invoice can be
|
|
3
|
+
* shown as an amount and a description instead of a wall of characters. It
|
|
4
|
+
* checks the bech32 checksum but not the signature: this is for display, the
|
|
5
|
+
* wallet that pays is the one that must verify.
|
|
6
|
+
*/
|
|
7
|
+
export interface Bolt11Invoice {
|
|
8
|
+
/** The invoice as it should be handed to a wallet: lower case, no `lightning:` prefix. */
|
|
9
|
+
invoice: string;
|
|
10
|
+
network: "bitcoin" | "testnet" | "signet" | "regtest";
|
|
11
|
+
/** Null for an invoice that lets the payer choose the amount. */
|
|
12
|
+
amountMsat: bigint | null;
|
|
13
|
+
/** Rounded up to whole sats; null when the payer chooses. */
|
|
14
|
+
amountSat: number | null;
|
|
15
|
+
/** Seconds since the UNIX epoch. */
|
|
16
|
+
createdAt: number;
|
|
17
|
+
expiresAt: number;
|
|
18
|
+
description?: string;
|
|
19
|
+
/** The `h` tag: sha256 of a description the invoice does not carry (LNURL-pay invoices commit to their metadata this way). */
|
|
20
|
+
descriptionHash?: string;
|
|
21
|
+
paymentHash?: string;
|
|
22
|
+
}
|
|
23
|
+
/** Finds an invoice inside free text. The match still has to pass `decodeBolt11`. */
|
|
24
|
+
export declare const BOLT11_PATTERN: RegExp;
|
|
25
|
+
export declare function decodeBolt11(text: string): Bolt11Invoice | null;
|
|
26
|
+
/** The first valid invoice in a chat message, with whatever else the message says. */
|
|
27
|
+
export declare function findBolt11(text: string): {
|
|
28
|
+
invoice: Bolt11Invoice;
|
|
29
|
+
rest: string;
|
|
30
|
+
} | null;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export declare function utf8Encode(str: string): Uint8Array;
|
|
2
|
+
export declare function utf8Decode(bytes: Uint8Array): string;
|
|
3
|
+
export declare function concatBytes(...parts: Uint8Array[]): Uint8Array;
|
|
4
|
+
export declare function bytesEqual(a: Uint8Array, b: Uint8Array): boolean;
|
|
5
|
+
export declare function toBase64(bytes: Uint8Array): string;
|
|
6
|
+
export declare function fromBase64(str: string): Uint8Array;
|
|
7
|
+
export declare function toBase64Url(bytes: Uint8Array): string;
|
|
8
|
+
export declare function fromBase64Url(str: string): Uint8Array;
|
|
9
|
+
export declare function toZ32(bytes: Uint8Array): string;
|
|
10
|
+
export declare function fromZ32(str: string): Uint8Array;
|
|
11
|
+
export declare function randomBytes(length: number): Uint8Array;
|
|
@@ -0,0 +1,232 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Signaling for voice/video calls, carried in the `_call` record. A full SDP
|
|
3
|
+
* does not fit in a Pkarr packet, so only the session-specific parameters
|
|
4
|
+
* travel and each side rebuilds the SDP around them.
|
|
5
|
+
*/
|
|
6
|
+
export interface CallSignal {
|
|
7
|
+
/**
|
|
8
|
+
* offer, answer, hang-up, "my picture changed" while the call is up, or `r`: an offer that restarts ICE on the
|
|
9
|
+
* call's own connection after its path was lost (WISP 601, "Reconnecting"). An app that does not know `r` drops it.
|
|
10
|
+
*/
|
|
11
|
+
t: "o" | "a" | "h" | "v" | "r";
|
|
12
|
+
/** The sender's clock when it made the signal: its order among that sender's signals. */
|
|
13
|
+
ts: number;
|
|
14
|
+
/** When this device heard a contact's signal, by its own clock. Never sent: the engine sets it (`heardCallSignal`). */
|
|
15
|
+
at?: number;
|
|
16
|
+
/**
|
|
17
|
+
* On an answer: the `ts` of the offer it answers, so the caller takes it for that offer and no other, whatever the two
|
|
18
|
+
* clocks say. Apps up to 1.0.2 send none and ignore it; they take an answer only when its `ts` is later than their
|
|
19
|
+
* offer's, which a callee whose clock is behind by longer than it took to answer never met.
|
|
20
|
+
*/
|
|
21
|
+
o?: number;
|
|
22
|
+
u?: string;
|
|
23
|
+
p?: string;
|
|
24
|
+
f?: string;
|
|
25
|
+
s?: string;
|
|
26
|
+
m?: string[];
|
|
27
|
+
c?: string[];
|
|
28
|
+
ss?: number[];
|
|
29
|
+
/** 1 while this peer is sending a picture, 0 while it is not. */
|
|
30
|
+
v?: number;
|
|
31
|
+
/** What the picture is: the camera or a screen. Only meaningful with `v: 1`. */
|
|
32
|
+
k?: "c" | "s";
|
|
33
|
+
/**
|
|
34
|
+
* The payload types the sender's SDP gives Opus and VP8, when not 111 and 96 (the rebuilt SDP's own, and
|
|
35
|
+
* Chromium's). WebKit offers H264 as 96 and VP8 as 106: rebuilt as `96 VP8`, the offerer read the answerer's
|
|
36
|
+
* VP8 as H264 and never showed its picture.
|
|
37
|
+
*/
|
|
38
|
+
ap?: number;
|
|
39
|
+
vp?: number;
|
|
40
|
+
/**
|
|
41
|
+
* On a hang-up, why when it was not the person's choice: `u`, the call could not connect (no connection found a
|
|
42
|
+
* candidate, or it did not connect in time). Older apps read it as a plain hang-up.
|
|
43
|
+
*/
|
|
44
|
+
r?: "u";
|
|
45
|
+
/**
|
|
46
|
+
* On an offer or an answer: 1 when this side can restart ICE on the call's connection, so a call both sides said
|
|
47
|
+
* it on reconnects after a network change instead of ending. Older apps leave it out, and ignore it.
|
|
48
|
+
*/
|
|
49
|
+
x?: 1;
|
|
50
|
+
/** On the answer to a restart offer (`r`): that offer's `ts`, so an answer to an older one is told apart. */
|
|
51
|
+
re?: number;
|
|
52
|
+
/**
|
|
53
|
+
* On an offer or an answer: 0 when this side takes no picture and sends none (the headless CLI: a bot has no screen
|
|
54
|
+
* to show one on). Its video section is rebuilt closed (`a=inactive`), so the other side sends nothing on it, a
|
|
55
|
+
* camera turned on mid-call included. Older apps leave it out, and ignore it: they send a picture nobody reads.
|
|
56
|
+
*/
|
|
57
|
+
vr?: 0;
|
|
58
|
+
}
|
|
59
|
+
export type CallState = "idle" | "offering" | "incoming" | "answering" | "connecting" | "connected" | "ended";
|
|
60
|
+
export type CallEventType = "call_started" | "call_received" | "call_connected" | "call_ended" | "call_missed"
|
|
61
|
+
/** Our call rang out (`RING_MS`) with nobody answering: the caller's line, as "Missed call" is the side it rang. */
|
|
62
|
+
| "call_unanswered"
|
|
63
|
+
/** We hung up our call while it still rang, before any answer. */
|
|
64
|
+
| "call_cancelled" | "call_rejected"
|
|
65
|
+
/** The call ended without ever connecting: no way to reach the contact was found, or none worked in time. */
|
|
66
|
+
| "call_failed";
|
|
67
|
+
/**
|
|
68
|
+
* Where a call's media comes from: the browser's own WebRTC and capture, or a stand-in with the same shape.
|
|
69
|
+
* Ghostly Desktop on Linux brings one: WebKitGTK has no WebRTC there, so GStreamer runs the call (WISP 601).
|
|
70
|
+
*/
|
|
71
|
+
export interface CallMedia {
|
|
72
|
+
createPeerConnection(config: RTCConfiguration): RTCPeerConnection;
|
|
73
|
+
getUserMedia(constraints: MediaStreamConstraints): Promise<MediaStream>;
|
|
74
|
+
/** Left out where the screen cannot be shared. */
|
|
75
|
+
getDisplayMedia?(options: DisplayMediaStreamOptions): Promise<MediaStream>;
|
|
76
|
+
/**
|
|
77
|
+
* Its connections restart ICE as a browser's do: `createOffer({ iceRestart: true })` on a connected one gives an
|
|
78
|
+
* offer with new ICE credentials and candidates, and a remote offer with new credentials is answered on the same
|
|
79
|
+
* connection (WISP 601, "Reconnecting"). The browser's own media does; a stand-in says so.
|
|
80
|
+
*/
|
|
81
|
+
restartsIce?: boolean;
|
|
82
|
+
/** Why the screen cannot be shared, where it cannot: the call window shows it on the share button, turned off. */
|
|
83
|
+
screenUnavailable?: string;
|
|
84
|
+
/**
|
|
85
|
+
* `getUserMedia` captures from the `deviceId` asked for, and `replaceTrack` on the audio sender switches the
|
|
86
|
+
* microphone: the profile's devices and the call's device menu work as with the browser's own media.
|
|
87
|
+
*/
|
|
88
|
+
choosesDevices?: boolean;
|
|
89
|
+
}
|
|
90
|
+
export declare function compressSdp(sdp: string): string;
|
|
91
|
+
export declare function decompressSdp(compressed: string): string;
|
|
92
|
+
export declare const RTC_CONFIG: RTCConfiguration;
|
|
93
|
+
/** An ICE server as a profile's settings keep it: one or more URLs in `urls` (space or comma separated). */
|
|
94
|
+
export interface CallIceServer {
|
|
95
|
+
urls: string | string[];
|
|
96
|
+
username?: string;
|
|
97
|
+
credential?: string;
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* A call's WebRTC configuration: the apps' STUN servers, then the profile's own (Settings → Network → ICE
|
|
101
|
+
* servers: a TURN relay, typically). A relay is what connects a call when no direct path works: a VPN that takes
|
|
102
|
+
* every packet through its tunnel, or a NAT that maps each destination apart.
|
|
103
|
+
*/
|
|
104
|
+
export declare function callRtcConfig(extra?: readonly CallIceServer[]): RTCConfiguration;
|
|
105
|
+
/**
|
|
106
|
+
* How many candidates a signal on the chat session carries (`paired-call`, WISP 601): the receiver takes eight.
|
|
107
|
+
* A compatibility chat's `_call` record keeps to one host and one server reflexive candidate (a DHT packet's worth).
|
|
108
|
+
*/
|
|
109
|
+
export declare const PAIRED_CALL_CANDIDATES = 8;
|
|
110
|
+
/**
|
|
111
|
+
* The candidates a signal carries, from the `a=candidate:` values of an SDP, when it may carry up to `max`.
|
|
112
|
+
*
|
|
113
|
+
* A computer often has several interfaces (Wi-Fi, Ethernet, VM bridges, Tailscale, a VPN) and the one listed first is
|
|
114
|
+
* not always one the contact can reach: on a Mac with a VPN as its default route it is the tunnel's address, which
|
|
115
|
+
* nothing on that machine can answer. So the signal carries every usable path, in this order:
|
|
116
|
+
*
|
|
117
|
+
* 1. host candidates on local networks, IPv4 or an mDNS name (at most four);
|
|
118
|
+
* 2. the first server reflexive candidate, and relay candidates (a TURN server, when the profile has one);
|
|
119
|
+
* 3. IPv6 host candidates, global ones first (at most two);
|
|
120
|
+
* 4. host candidates a browser marks as costly (`network-cost` 50 or more: a VPN, or an interface it does not know);
|
|
121
|
+
* 5. whatever else fits.
|
|
122
|
+
*
|
|
123
|
+
* UDP only, loopback, link-local and unspecified addresses left out (loopback kept with `loopback`), the related
|
|
124
|
+
* address dropped (it is informational, and an IPv6 one broke apps before 0.5).
|
|
125
|
+
*/
|
|
126
|
+
export declare function pickCallCandidates(candidates: readonly string[], max?: number, { loopback }?: {
|
|
127
|
+
loopback?: boolean | undefined;
|
|
128
|
+
}): string[];
|
|
129
|
+
/**
|
|
130
|
+
* The parameters of a call signal, from an SDP. `maxCandidates` above two (a signal on the chat session) carries
|
|
131
|
+
* the candidates `pickCallCandidates` chooses; the default keeps a compatibility chat's one host and one server
|
|
132
|
+
* reflexive candidate.
|
|
133
|
+
*/
|
|
134
|
+
export declare function extractParamsFromSdp(sdp: string, { maxCandidates, loopback }?: {
|
|
135
|
+
maxCandidates?: number;
|
|
136
|
+
loopback?: boolean;
|
|
137
|
+
}): Partial<CallSignal>;
|
|
138
|
+
/** Offers, answers and hang-ups older (or further in the future) than this are ignored. */
|
|
139
|
+
export declare const CALL_SIGNAL_MAX_AGE_MS = 120000;
|
|
140
|
+
/**
|
|
141
|
+
* A signal dated further ahead of this clock than this is not taken, however it was heard. A receiver acts on a signal
|
|
142
|
+
* only when its `ts` is later than the last one it acted on: taken, a signal dated a day ahead would be that last one,
|
|
143
|
+
* and every offer, answer and hang-up its sender made afterwards would be dropped as older, until the app started again.
|
|
144
|
+
*/
|
|
145
|
+
export declare const CALL_SIGNAL_FUTURE_MS: number;
|
|
146
|
+
/**
|
|
147
|
+
* Validates an untrusted `_call` signal (from the Pkarr record or a `call`
|
|
148
|
+
* frame). Every value that ends up in the rebuilt SDP is checked against an
|
|
149
|
+
* anchored pattern and candidates are re-serialized from their parts, so a peer
|
|
150
|
+
* cannot inject SDP lines. Signals outside {@link CALL_SIGNAL_MAX_AGE_MS} of
|
|
151
|
+
* `now` are rejected so that a stale packet does not ring.
|
|
152
|
+
*/
|
|
153
|
+
export declare function parseCallSignal(json: string, now?: number): CallSignal | null;
|
|
154
|
+
/**
|
|
155
|
+
* A contact's signal as the engine hands it on: `at` says when this device heard it, by its own clock (absent: nothing
|
|
156
|
+
* says, as for one found in a record). Whatever `at` the signal came with is dropped: it is never the sender's to say.
|
|
157
|
+
*
|
|
158
|
+
* A signal's `ts` is its sender's clock. It orders that sender's signals, and settles two calls made at once the same
|
|
159
|
+
* way on both sides. It cannot say how long ago the signal was made, nor whether it came before or after something this
|
|
160
|
+
* device did: two devices' clocks are often minutes apart. Held against this clock, a contact two minutes off never
|
|
161
|
+
* rang here, and an answer from a contact whose clock was behind by longer than it took to answer was dropped as
|
|
162
|
+
* "from before the offer", so the call never connected.
|
|
163
|
+
*/
|
|
164
|
+
export declare function heardCallSignal(json: string, at?: number): string;
|
|
165
|
+
/**
|
|
166
|
+
* When a contact's signal came, to hold against something this device did (its own offer): on this clock when the
|
|
167
|
+
* engine said (`at`), by the signal's own time otherwise, as before.
|
|
168
|
+
*/
|
|
169
|
+
export declare const callSignalHeardAt: (signal: Pick<CallSignal, "ts" | "at">) => number;
|
|
170
|
+
/**
|
|
171
|
+
* Whether a contact's answer is for the offer this side made at `offerTs` (its own clock). An answer that names its
|
|
172
|
+
* offer (`o`) says so itself. One that names none (an app up to 1.0.2) is taken when it came after this side offered.
|
|
173
|
+
*/
|
|
174
|
+
export declare function answersOffer(answer: Pick<CallSignal, "ts" | "at" | "o">, offerTs: number): boolean;
|
|
175
|
+
/**
|
|
176
|
+
* Whether the peer that sent this offer or answer is sending a picture.
|
|
177
|
+
*
|
|
178
|
+
* Since v2 every call negotiates a video section, on or off, so the media list
|
|
179
|
+
* no longer answers this: `v` does. A v1 peer sends no `v`, and there the video
|
|
180
|
+
* section only carries an SSRC when it is really sending on it.
|
|
181
|
+
*/
|
|
182
|
+
export declare function signalHasVideo(signal: CallSignal | null): boolean;
|
|
183
|
+
/**
|
|
184
|
+
* Rebuilds an SDP around a signal. Only pass signals returned by {@link parseCallSignal}.
|
|
185
|
+
*
|
|
186
|
+
* Offer and answer are built the same way: which of the two this is comes from
|
|
187
|
+
* the signal itself, as `a=setup:`, not from the caller.
|
|
188
|
+
*/
|
|
189
|
+
export declare function buildSdpFromSignal(signal: CallSignal): string;
|
|
190
|
+
/** Whether a description carries any candidate: one without cannot be reached, nor reach anyone. */
|
|
191
|
+
export declare function sdpHasCandidates(sdp: string | undefined | null): boolean;
|
|
192
|
+
/**
|
|
193
|
+
* Whether an ICE candidate is a UDP host candidate on a globally routable IPv4 address. A device on such an address (no
|
|
194
|
+
* NAT) is told that very address and port by a STUN server, and Chromium drops a reflexive candidate equal to a host
|
|
195
|
+
* one: no `typ srflx` ever comes. It shows the host's address only when it does not hide it behind an mDNS name (once
|
|
196
|
+
* the origin may use the camera or the microphone), which is also when it drops that reflexive candidate. The host
|
|
197
|
+
* candidate then says what the reflexive one would have.
|
|
198
|
+
*/
|
|
199
|
+
export declare function isGlobalIpv4Host(candidate: string): boolean;
|
|
200
|
+
/**
|
|
201
|
+
* Resolves when the local description is good enough to publish. Waiting for
|
|
202
|
+
* gathering to *complete* takes the full timeout whenever one STUN server or
|
|
203
|
+
* address family does not answer, which made every call ring ~10 s late. The
|
|
204
|
+
* signal only carries a host and a server reflexive candidate anyway (plus a
|
|
205
|
+
* relay one when TURN is configured), so that is what is waited for. Without
|
|
206
|
+
* TURN, a host candidate on a global IPv4 address counts as the reflexive one
|
|
207
|
+
* (`isGlobalIpv4Host`): a device with no NAT gets none, and its offers waited
|
|
208
|
+
* the whole timeout whenever gathering did not complete.
|
|
209
|
+
*/
|
|
210
|
+
export declare function waitForIceGathering(pc: RTCPeerConnection, timeoutMs?: number,
|
|
211
|
+
/**
|
|
212
|
+
* Give up after this long when not a single candidate showed up. Host candidates come in a few milliseconds; a
|
|
213
|
+
* connection with none by then has stalled (Chromium, rarely, under load) and will not find any later.
|
|
214
|
+
*/
|
|
215
|
+
{ stallMs,
|
|
216
|
+
/**
|
|
217
|
+
* The description was just set on a connection that gathered before (an ICE restart): "complete" may still be
|
|
218
|
+
* the last round's, so it only counts once the description has a candidate of this round.
|
|
219
|
+
*/
|
|
220
|
+
fresh,
|
|
221
|
+
/** How long to keep collecting after the candidate waited for showed up (`ICE_SETTLE_MS` by default). */
|
|
222
|
+
settleMs,
|
|
223
|
+
/**
|
|
224
|
+
* Give up waiting for that candidate after this long once the connection has any candidate (a host one comes in
|
|
225
|
+
* milliseconds): what was gathered by then goes. Unset: up to `timeoutMs`.
|
|
226
|
+
*/
|
|
227
|
+
hostBoundMs, }?: {
|
|
228
|
+
stallMs?: number;
|
|
229
|
+
fresh?: boolean;
|
|
230
|
+
settleMs?: number;
|
|
231
|
+
hostBoundMs?: number;
|
|
232
|
+
}): Promise<void>;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/** A value JSON can hold. */
|
|
2
|
+
export type JsonValue = null | boolean | number | string | JsonValue[] | {
|
|
3
|
+
[key: string]: JsonValue;
|
|
4
|
+
};
|
|
5
|
+
/** The canonical text of a JSON value. Throws on a value JSON cannot hold (a non-finite number, a lone surrogate). */
|
|
6
|
+
export declare function canonicalJson(value: unknown): string;
|
|
7
|
+
/** The canonical UTF-8 bytes of a JSON value. */
|
|
8
|
+
export declare function canonicalJsonBytes(value: unknown): Uint8Array;
|
|
9
|
+
export type CanonicalJsonRefusal = "not-json" | "not-canonical";
|
|
10
|
+
export type CanonicalJsonReading = {
|
|
11
|
+
ok: true;
|
|
12
|
+
value: JsonValue;
|
|
13
|
+
} | {
|
|
14
|
+
ok: false;
|
|
15
|
+
reason: CanonicalJsonRefusal;
|
|
16
|
+
detail?: string;
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* Reads bytes that must be the canonical form of a JSON value: `not-json` when they are not UTF-8 JSON, `not-canonical`
|
|
20
|
+
* when writing the value again gives other bytes.
|
|
21
|
+
*/
|
|
22
|
+
export declare function readCanonicalJson(bytes: Uint8Array): CanonicalJsonReading;
|