@vordium/sdk 0.2.0 → 0.2.2

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.
@@ -0,0 +1,141 @@
1
+ import { VordiumError } from './errors.js';
2
+ import type { Transport } from './http.js';
3
+ import { type NonceStore } from './nonce.js';
4
+ /**
5
+ * The signed release record: the genesis, chain id and deposit bridge of each network, signed by the release key.
6
+ *
7
+ * A network's identity is taken from `releases.json`, and only after its detached OpenPGP signature
8
+ * (`releases.json.asc`) verifies under the release key that ships in this package ({@link RELEASE_KEY}, fingerprint
9
+ * {@link RELEASE_KEY_FINGERPRINT}). The signature covers the exact bytes as served; the record is read from those same
10
+ * bytes only after the signature holds.
11
+ *
12
+ * The key is pinned by its fingerprint. Its expiry is read from its newest self-signature. When that expiry is near
13
+ * ({@link KEY_REFRESH_BEFORE_S}) or past, the key is read again from where it is served ({@link KEY_URLS}). A served copy
14
+ * is used only when it is the same key (same fingerprint and point) and its self-signature verifies under that key: its
15
+ * newest self-signature then gives the expiry. A revocation that verifies under the key refuses every record. Nothing
16
+ * else is taken from a served copy, and when none can be read the shipped key is used as it is.
17
+ *
18
+ * Everything else is checked here, with no other program: the ASCII armour (and its CRC-24), the version 4 signature packet (EdDSA over Ed25519, SHA-256 or SHA-512),
19
+ * its hashed subpackets, the issuer fingerprint, the signature hash over the data and the hashed trailer, and the
20
+ * Ed25519 signature itself (RFC 8032).
21
+ */
22
+ /** The release key: every network record must be signed by it. */
23
+ export declare const RELEASE_KEY_FINGERPRINT = "C5EB4728F660369CE519D834B48FB4B71EFD48AE";
24
+ export declare const RELEASE_KEY = "-----BEGIN PGP PUBLIC KEY BLOCK-----\n\nmDMEaqXHBhYJKwYBBAHaRw8BAQdA8NRFgXw3NaEYFesojdDl1TlSlk9O5bXhsM4i\no7k3e+q0J1ZvcmRpdW0gUmVsZWFzZXMgPHJlbGVhc2VzQHZvcmRpdW0uY29tPoi1\nBBMWCgBdFiEExetHKPZgNpzlGdg0tI+0tx79SK4FAmqlxwYbFIAAAAAABAAObWFu\ndTIsMi41KzEuMTIsMCwzAhsDBQkDwmcABQsJCAcCAiICBhUKCQgLAgQWAgMBAh4H\nAheAAAoJELSPtLce/UiuMUgA/2VojVnml+DJHQ6xbxhnbrNeD5p8H4lXsVASdpvs\nRsCIAQCkMr8M76++QNGj08s+apf7CDgEVwbBFo4shxsYAU+gDw==\n=20lT\n-----END PGP PUBLIC KEY BLOCK-----\n";
25
+ /** Where each named network's record is read, in order. The signature is read at the same address + ".asc". */
26
+ export declare const RELEASE_RECORD_URLS: Readonly<Record<'mainnet' | 'testnet', readonly string[]>>;
27
+ /** The record format this SDK reads. */
28
+ export declare const RELEASE_RECORD_SCHEMA = "vordium.release-record/3";
29
+ /** Where the release key is served. Read only when the key's expiry is near or past (see {@link refreshKey}). */
30
+ export declare const KEY_URLS: readonly string[];
31
+ /** The key is read again from {@link KEY_URLS} from this long (seconds) before its expiry. */
32
+ export declare const KEY_REFRESH_BEFORE_S: number;
33
+ /** A key read from {@link KEY_URLS} is used for this long (seconds) before it is read again. */
34
+ export declare const KEY_REFRESH_TTL_S: number;
35
+ /** A read that left an expired key as it was is tried again after this long (seconds). */
36
+ export declare const KEY_RETRY_S = 30;
37
+ /** The release record cannot be used. `code` names the reason; the message is a plain sentence. */
38
+ export declare class RecordRefused extends VordiumError {
39
+ constructor(code: string, message: string);
40
+ }
41
+ export declare function crc24(data: Uint8Array): number;
42
+ /** The bytes inside one ASCII-armoured block of `kind` ("PGP SIGNATURE", "PGP PUBLIC KEY BLOCK"). The CRC-24 line, when
43
+ * present, must match. Throws {@link RecordRefused}. */
44
+ export declare function dearmor(text: string | Uint8Array, kind: string): Uint8Array;
45
+ /** An Ed25519 OpenPGP public key: its v4 fingerprint (40 upper-case hex), its 32-byte point, and when it expires
46
+ * (seconds; null = never), read from its newest self-signature that verifies. */
47
+ export interface PublicKey {
48
+ fingerprint: string;
49
+ point: Uint8Array;
50
+ expires: number | null;
51
+ /** The time of the self-signature the expiry was read from. */
52
+ signedAt: number;
53
+ /** A key revocation signature by this key verifies. */
54
+ revoked: boolean;
55
+ }
56
+ /** The primary key of an armoured public key block. The fingerprint is computed from the key packet (SHA-1 over
57
+ * 0x99 || length || packet). Only a version 4 EdDSA key on Ed25519 is accepted, with at least one user ID whose
58
+ * self-signature verifies; the newest such self-signature gives the key's expiry. */
59
+ export declare function parsePublicKey(armoured: string | Uint8Array): PublicKey;
60
+ /** A checked detached signature: who made it (issuer fingerprint) and when (seconds). */
61
+ export interface SignatureInfo {
62
+ fingerprint: string;
63
+ created: number;
64
+ }
65
+ /**
66
+ * Verify an armoured detached signature over the exact bytes `data` under one of `keys` (the pinned keys). Returns the
67
+ * signature's issuer and time; throws {@link RecordRefused} with a plain sentence otherwise.
68
+ */
69
+ export declare function verifyDetached(data: Uint8Array, armouredSig: string | Uint8Array, keys: readonly PublicKey[], nowSec?: number): SignatureInfo;
70
+ /** The deposit bridge as the signed record names it (addresses lower-case). */
71
+ export interface RecordBridge {
72
+ chainId: number;
73
+ vault: string;
74
+ handler: string;
75
+ usdc: string;
76
+ }
77
+ /** One network of a signed record. */
78
+ export interface RecordNetwork {
79
+ chainId: number;
80
+ genesis: string;
81
+ bridge: RecordBridge;
82
+ retiredGenesis: readonly string[];
83
+ name: string | null;
84
+ }
85
+ /** A signed record, read from the verified bytes. Times are in seconds. */
86
+ export interface ReleaseRecord {
87
+ sequence: number;
88
+ issuedAt: number;
89
+ validUntil: number;
90
+ networks: ReadonlyMap<number, RecordNetwork>;
91
+ signedBy: string;
92
+ }
93
+ /** JSON.parse that refuses a key given twice in one object (two readers could otherwise take different values). */
94
+ export declare function parseStrictJson(text: string): unknown;
95
+ /** Whether bytes that could not be verified claim to be a network record (a JSON object with `networks`). Used only to
96
+ * tell an unsigned record (refused) from another file (ignored); no value of it is ever used. */
97
+ export declare function isNetworkRecord(data: Uint8Array): boolean;
98
+ /** The record in the VERIFIED bytes `data`. Null when the file is not a network record (it has no `networks`: the
99
+ * release list of an earlier format). Throws {@link RecordRefused} for a record that is not well formed. */
100
+ export declare function parseRecord(data: Uint8Array, signedBy?: string): ReleaseRecord | null;
101
+ /** A verified record and the entry of the network it was read for. */
102
+ export interface VerifiedRecord {
103
+ record: ReleaseRecord;
104
+ entry: RecordNetwork;
105
+ url: string;
106
+ }
107
+ export interface RefreshKeyOptions {
108
+ transport: Transport;
109
+ urls?: readonly string[];
110
+ timeoutMs?: number;
111
+ }
112
+ /**
113
+ * `key` as its newest served copy states it. A copy at `urls` (default {@link KEY_URLS}, through `transport.getBytes`) is
114
+ * used only when it parses as the same key (same fingerprint and point, a self-signature that verifies under that key)
115
+ * and its newest self-signature is newer than the one `key` was read from; a copy carrying a revocation that verifies
116
+ * under the key gives the key as revoked. A copy that cannot be read, is another key or is older is skipped; with none
117
+ * usable, `key` is returned as it is.
118
+ */
119
+ export declare function refreshKey(key: PublicKey, opts: RefreshKeyOptions): Promise<PublicKey>;
120
+ /** The keys a record must be signed by: the shipped release key, or (tests only) the armoured keys given. The shipped
121
+ * key's expiry is refreshed by {@link readRecord} from its served copy when near or past (see {@link refreshKey}). */
122
+ export declare function pinnedKeys(releaseKeys?: readonly string[]): PublicKey[];
123
+ export interface ReadRecordOptions {
124
+ transport: Transport;
125
+ timeoutMs?: number;
126
+ /** Where the highest sequence seen is kept (default: the nonce store, files 0600 under Node.js). */
127
+ store?: NonceStore;
128
+ /** This computer's clock in milliseconds (tests replace it). */
129
+ now?: () => number;
130
+ }
131
+ /**
132
+ * Read the signed record for `chainId` from the first of `urls` that serves one (through `transport.getBytes`; a
133
+ * transport without it reads no record).
134
+ *
135
+ * Resolves null when no address serves a network record (nothing, or a signed release list of an earlier format) and no
136
+ * record for this network was seen on this computer before. Throws {@link RecordRefused} (with a plain sentence) for an
137
+ * unsigned record, a bad signature, another key, a record of an unknown format, an expired record, a sequence lower than
138
+ * one seen before, a record that does not list `chainId`, or, when a record for this network was seen before, for no
139
+ * record served now.
140
+ */
141
+ export declare function readRecord(chainId: number, urls: readonly string[], keys: readonly PublicKey[], opts: ReadRecordOptions): Promise<VerifiedRecord | null>;