wasmlock 0.0.0-stage → 0.1.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/LICENSE +21 -0
- package/README.md +244 -2
- package/THIRD_PARTY_NOTICES.txt +580 -0
- package/dist/add.d.ts +38 -0
- package/dist/atomic.d.ts +12 -0
- package/dist/check-format.d.ts +5 -0
- package/dist/check.d.ts +120 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +40474 -0
- package/dist/config.d.ts +18 -0
- package/dist/diff-format.d.ts +19 -0
- package/dist/diff-pending.d.ts +26 -0
- package/dist/diff.d.ts +85 -0
- package/dist/entry.d.ts +37 -0
- package/dist/exit.d.ts +15 -0
- package/dist/index.d.ts +40 -0
- package/dist/index.js +40093 -0
- package/dist/interface-diff.d.ts +66 -0
- package/dist/json.d.ts +11 -0
- package/dist/ledger.d.ts +43 -0
- package/dist/lockfile.d.ts +100 -0
- package/dist/network.d.ts +5 -0
- package/dist/pending.d.ts +38 -0
- package/dist/rpc.d.ts +141 -0
- package/dist/rules.d.ts +109 -0
- package/dist/snapshot.d.ts +96 -0
- package/dist/spec.d.ts +25 -0
- package/dist/strkey.d.ts +2 -0
- package/dist/typestring.d.ts +22 -0
- package/dist/untrusted.d.ts +91 -0
- package/dist/update-report.d.ts +14 -0
- package/dist/update.d.ts +82 -0
- package/dist/upgrade.d.ts +227 -0
- package/dist/version.d.ts +2 -0
- package/dist/wasm.d.ts +40 -0
- package/package.json +48 -4
- package/schema/wasmlock-rules.schema.json +90 -0
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import type { MetaEntry, ImportEntry } from "./lockfile.ts";
|
|
2
|
+
import { type Snapshot } from "./snapshot.ts";
|
|
3
|
+
/**
|
|
4
|
+
* The interface diff: pure functions over two snapshots and the integrator's `uses`.
|
|
5
|
+
*
|
|
6
|
+
* Classes, from most to least serious:
|
|
7
|
+
* - `breaking`: a function or type the integrator uses changed in a way that can fail a call.
|
|
8
|
+
* - `potentially-breaking`: the same, but `uses` is not declared, so every function counts as used.
|
|
9
|
+
* - `may-break-matchers`: a union case was added; code that matches on the union exhaustively may no longer compile.
|
|
10
|
+
* - `non-breaking`: a change exists but does not touch what is used (or is a removal of unreferenced spec).
|
|
11
|
+
* - `informational`: additions, meta, imports, events.
|
|
12
|
+
*/
|
|
13
|
+
export type Classification = "breaking" | "potentially-breaking" | "may-break-matchers" | "non-breaking" | "informational";
|
|
14
|
+
export declare const CLASSIFICATIONS: readonly Classification[];
|
|
15
|
+
export type Area = "function" | "type" | "error" | "event" | "meta" | "import";
|
|
16
|
+
export interface InterfaceChange {
|
|
17
|
+
readonly area: Area;
|
|
18
|
+
/** The function, type, error enum, event, meta key or import the change belongs to. */
|
|
19
|
+
readonly name: string;
|
|
20
|
+
/** A struct field, union case, enum case or error code, when the change is inside an item. */
|
|
21
|
+
readonly member?: string;
|
|
22
|
+
/** A stable machine-readable kind, such as `removed` or `field-retyped`. */
|
|
23
|
+
readonly change: string;
|
|
24
|
+
readonly classification: Classification;
|
|
25
|
+
/**
|
|
26
|
+
* For a person. It holds names and values read from the contract's code, so it is data: a
|
|
27
|
+
* formatter never writes it as it is but through `messageForTerminal` or `messageForMarkdown`.
|
|
28
|
+
*/
|
|
29
|
+
readonly message: string;
|
|
30
|
+
/** The value before and after (an item, a signature or a string). Absent for an addition or removal. */
|
|
31
|
+
readonly old?: unknown;
|
|
32
|
+
readonly new?: unknown;
|
|
33
|
+
/** Meta only: a key worth a second look (toolchain, source or build keys). */
|
|
34
|
+
readonly notable?: true;
|
|
35
|
+
}
|
|
36
|
+
/** A type that left the spec and that no function of the old interface referenced. Never breaking. */
|
|
37
|
+
export interface UnreferencedRemoval {
|
|
38
|
+
readonly name: string;
|
|
39
|
+
readonly kind: "struct" | "union" | "enum" | "error";
|
|
40
|
+
}
|
|
41
|
+
export interface InterfaceDiff {
|
|
42
|
+
readonly changes: readonly InterfaceChange[];
|
|
43
|
+
readonly unreferencedRemovals: readonly UnreferencedRemoval[];
|
|
44
|
+
}
|
|
45
|
+
/** `uses` names a function that the pinned interface does not have. A usage error. */
|
|
46
|
+
export declare class UsesError extends Error {
|
|
47
|
+
readonly unknown: readonly string[];
|
|
48
|
+
constructor(unknown: readonly string[]);
|
|
49
|
+
}
|
|
50
|
+
/** Throws {@link UsesError} when `uses` names a function the snapshot does not have. */
|
|
51
|
+
export declare function assertUsesKnown(snapshot: Snapshot, uses: readonly string[] | undefined): void;
|
|
52
|
+
declare function sortChanges(changes: readonly InterfaceChange[]): InterfaceChange[];
|
|
53
|
+
/**
|
|
54
|
+
* Diffs two interfaces for an integrator. `uses` is the list of functions they call; `undefined`
|
|
55
|
+
* means undeclared, and then every function counts as used and the serious classes read
|
|
56
|
+
* `potentially-breaking`. Throws {@link UsesError} when `uses` names a function the old interface
|
|
57
|
+
* does not have.
|
|
58
|
+
*/
|
|
59
|
+
export declare function diffSnapshots(oldS: Snapshot, newS: Snapshot, uses: readonly string[] | undefined): InterfaceDiff;
|
|
60
|
+
/** Whether a meta key records the toolchain, the source or the build, which a re-pin should look at. */
|
|
61
|
+
export declare function isNotableMetaKey(key: string): boolean;
|
|
62
|
+
/** Meta differences. Always informational; toolchain, source and build keys are flagged notable. */
|
|
63
|
+
export declare function diffMeta(oldMeta: readonly MetaEntry[], newMeta: readonly MetaEntry[]): InterfaceChange[];
|
|
64
|
+
/** Host import differences, by name. Informational: an import list says nothing about behavior. */
|
|
65
|
+
export declare function diffImports(oldImports: readonly ImportEntry[], newImports: readonly ImportEntry[]): InterfaceChange[];
|
|
66
|
+
export { sortChanges };
|
package/dist/json.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export type JsonValue = null | boolean | number | string | readonly JsonValue[] | {
|
|
2
|
+
readonly [key: string]: JsonValue;
|
|
3
|
+
};
|
|
4
|
+
export declare function isRecord(value: unknown): value is Record<string, unknown>;
|
|
5
|
+
/**
|
|
6
|
+
* Finds object keys that appear twice in one object of syntactically valid JSON text. JSON.parse
|
|
7
|
+
* keeps the last value silently, which a pin file must never do. Returns the path of each repeat.
|
|
8
|
+
*/
|
|
9
|
+
export declare function findDuplicateKeys(text: string): string[];
|
|
10
|
+
/** Two-space JSON with every object's keys sorted and a trailing newline. */
|
|
11
|
+
export declare function canonicalJson(value: unknown): string;
|
package/dist/ledger.d.ts
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/** The ledger bytes are not what the schema says they are. Reported as an incomplete read. */
|
|
2
|
+
export declare class DecodeError extends Error {
|
|
3
|
+
constructor(message: string);
|
|
4
|
+
}
|
|
5
|
+
/** How an instance reaches its code, as the ledger states it. */
|
|
6
|
+
export type Executable = {
|
|
7
|
+
readonly kind: "wasm";
|
|
8
|
+
readonly wasmHash: string;
|
|
9
|
+
} | {
|
|
10
|
+
readonly kind: "stellar-asset";
|
|
11
|
+
} | {
|
|
12
|
+
readonly kind: "external";
|
|
13
|
+
readonly owner: string;
|
|
14
|
+
readonly tag: string;
|
|
15
|
+
}
|
|
16
|
+
/** An arm this version does not understand. The reader never guesses at it. */
|
|
17
|
+
| {
|
|
18
|
+
readonly kind: "unknown";
|
|
19
|
+
readonly arm: string;
|
|
20
|
+
};
|
|
21
|
+
export declare function instanceKey(contractId: string): string;
|
|
22
|
+
export declare function codeKey(wasmHash: string): string;
|
|
23
|
+
/** The owner's persistent entry that holds the hash a CAP-85 tag names. */
|
|
24
|
+
export declare function tagKey(owner: string, tag: string): string;
|
|
25
|
+
/** The executable of an instance entry (the `xdr` field of a `getLedgerEntries` result). */
|
|
26
|
+
export declare function decodeInstanceEntry(entryXdr: string): Executable;
|
|
27
|
+
/** The hash held by an owner's tag entry: 32 bytes, as lowercase hex. */
|
|
28
|
+
export declare function decodeTagEntry(entryXdr: string): string;
|
|
29
|
+
/** The hash of a code entry. The code bytes themselves are not needed to check a pin. */
|
|
30
|
+
export declare function decodeCodeEntry(entryXdr: string): string;
|
|
31
|
+
/** The code bytes of a code entry do not hash to the hash they were requested under. */
|
|
32
|
+
export declare class CodeHashMismatchError extends DecodeError {
|
|
33
|
+
constructor();
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* The code bytes of a code entry that was requested under `requestedHash`. A Soroban code hash is
|
|
37
|
+
* the SHA-256 of the Wasm bytes, so this proves that the provider served the code that was asked
|
|
38
|
+
* for: the entry must carry the requested hash in its key AND the bytes must hash to it. The bytes
|
|
39
|
+
* are hashed once, here, before anything parses them; a provider that serves other bytes under the
|
|
40
|
+
* hash gets a {@link CodeHashMismatchError} and its bytes are never parsed. `check` keeps to
|
|
41
|
+
* {@link decodeCodeEntry} and never touches the bytes.
|
|
42
|
+
*/
|
|
43
|
+
export declare function decodeVerifiedCode(entryXdr: string, requestedHash: string): Uint8Array;
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { type Network } from "./network.ts";
|
|
2
|
+
import { type Snapshot } from "./snapshot.ts";
|
|
3
|
+
export declare const LOCKFILE_VERSION = 1;
|
|
4
|
+
export declare const LOCKFILE_NAME = "wasmlock.json";
|
|
5
|
+
/** The instance runs a Wasm code entry directly. */
|
|
6
|
+
export interface WasmReach {
|
|
7
|
+
readonly kind: "wasm";
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* The instance points at an owner contract and a tag (CAP-85). The owner's persistent tag entry
|
|
11
|
+
* holds the hash, so it is pinned too: repointing the tag changes the code without touching the
|
|
12
|
+
* instance.
|
|
13
|
+
*/
|
|
14
|
+
export interface ExternalReach {
|
|
15
|
+
readonly kind: "external";
|
|
16
|
+
readonly owner: string;
|
|
17
|
+
readonly tag: string;
|
|
18
|
+
readonly ownerEntry: {
|
|
19
|
+
readonly hash: string;
|
|
20
|
+
readonly lastModifiedLedger: number;
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
export type Reach = WasmReach | ExternalReach;
|
|
24
|
+
/** The normalized contract spec. The item shapes are documented in the README and in `snapshot.ts`. */
|
|
25
|
+
export type InterfaceSnapshot = Snapshot;
|
|
26
|
+
export interface InterfaceRecord {
|
|
27
|
+
/**
|
|
28
|
+
* `sha256:` plus 64 lowercase hex characters, over the canonical JSON of the snapshot. When the
|
|
29
|
+
* snapshot is present the validator recomputes it and rejects a file whose digest differs.
|
|
30
|
+
*/
|
|
31
|
+
readonly digest: string;
|
|
32
|
+
readonly snapshot?: InterfaceSnapshot;
|
|
33
|
+
}
|
|
34
|
+
/** A host function a module imports. Informational: it says nothing about behavior. */
|
|
35
|
+
export interface ImportEntry {
|
|
36
|
+
readonly module: string;
|
|
37
|
+
readonly name: string;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* What the lockfile stores of a contract's meta, which is free-form text the contract's admin
|
|
41
|
+
* controls. A key longer than {@link META_KEY_MAX} or a value longer than {@link META_VALUE_MAX}
|
|
42
|
+
* code points is stored truncated, with a visible marker that says how many characters were dropped.
|
|
43
|
+
* At most {@link META_ENTRIES_MAX} entries are stored (keys that record the toolchain, source or
|
|
44
|
+
* build first, then the rest in sorted order), and when more existed one more entry, under
|
|
45
|
+
* {@link META_DROPPED_KEY}, records how many were left out. The validator holds a file to the same
|
|
46
|
+
* bounds, so a hostile contract cannot bloat the lockfile or a pull request.
|
|
47
|
+
*/
|
|
48
|
+
export declare const META_KEY_MAX = 256;
|
|
49
|
+
export declare const META_VALUE_MAX = 1024;
|
|
50
|
+
export declare const META_ENTRIES_MAX = 64;
|
|
51
|
+
export declare const META_DROPPED_KEY = "wasmlock.meta.dropped";
|
|
52
|
+
export interface MetaEntry {
|
|
53
|
+
readonly key: string;
|
|
54
|
+
readonly value: string;
|
|
55
|
+
}
|
|
56
|
+
export interface ContractEntry {
|
|
57
|
+
readonly id: string;
|
|
58
|
+
readonly label?: string;
|
|
59
|
+
readonly reach: Reach;
|
|
60
|
+
/** The code hash the pin trusts. For an external reach, the hash the owner's tag entry held. */
|
|
61
|
+
readonly wasmHash: string;
|
|
62
|
+
/** `lastModifiedLedgerSeq` of the code entry when pinned: where to find the code in ledger history. */
|
|
63
|
+
readonly codeLedgerHint: number;
|
|
64
|
+
/** `lastModifiedLedgerSeq` of the instance entry when pinned. Weak: storage writes move it too. */
|
|
65
|
+
readonly instanceLedgerHint: number;
|
|
66
|
+
/** The latest ledger the pin was read at. */
|
|
67
|
+
readonly pinnedAt: number;
|
|
68
|
+
readonly interface: InterfaceRecord;
|
|
69
|
+
readonly meta?: readonly MetaEntry[];
|
|
70
|
+
/** The module's host imports when pinned, sorted by module then name. */
|
|
71
|
+
readonly imports?: readonly ImportEntry[];
|
|
72
|
+
/** The functions the integrator calls. Absent means undeclared, not "none". */
|
|
73
|
+
readonly uses?: readonly string[];
|
|
74
|
+
/** Names of pending-upgrade rules to apply to this contract. */
|
|
75
|
+
readonly pending?: readonly string[];
|
|
76
|
+
}
|
|
77
|
+
export interface Lockfile {
|
|
78
|
+
readonly version: typeof LOCKFILE_VERSION;
|
|
79
|
+
readonly network: Network;
|
|
80
|
+
/** sha256 of the network passphrase, hex. Must agree with `network`. */
|
|
81
|
+
readonly networkId: string;
|
|
82
|
+
readonly contracts: readonly ContractEntry[];
|
|
83
|
+
}
|
|
84
|
+
export interface LockfileIssue {
|
|
85
|
+
readonly path: string;
|
|
86
|
+
readonly message: string;
|
|
87
|
+
}
|
|
88
|
+
export declare class LockfileError extends Error {
|
|
89
|
+
readonly issues: readonly LockfileIssue[];
|
|
90
|
+
constructor(issues: readonly LockfileIssue[]);
|
|
91
|
+
}
|
|
92
|
+
export declare const FUNCTION_NAME: RegExp;
|
|
93
|
+
/** Validates an already-parsed value. Throws {@link LockfileError} listing every problem found. */
|
|
94
|
+
export declare function validateLockfile(value: unknown): Lockfile;
|
|
95
|
+
/** Parses lockfile text: rejects invalid JSON, repeated keys and anything outside the schema. */
|
|
96
|
+
export declare function parseLockfile(text: string): Lockfile;
|
|
97
|
+
/** The one canonical text of a lockfile: sorted keys, sorted contracts, trailing newline. */
|
|
98
|
+
export declare function serializeLockfile(lockfile: Lockfile): string;
|
|
99
|
+
/** An empty lockfile for a network. */
|
|
100
|
+
export declare function emptyLockfile(network: Network): Lockfile;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export type Network = "mainnet" | "testnet";
|
|
2
|
+
export declare const NETWORK_PASSPHRASES: Readonly<Record<Network, string>>;
|
|
3
|
+
/** The network id: sha256 of the passphrase, as lowercase hex. */
|
|
4
|
+
export declare function networkIdOf(passphrase: string): string;
|
|
5
|
+
export declare function isNetwork(value: unknown): value is Network;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Evaluates pending-upgrade rules against the instance storage of one contract. Pure: it reads
|
|
3
|
+
* nothing, it only looks at the storage entries it is given.
|
|
4
|
+
*/
|
|
5
|
+
/** Printed with every pending report, in every format. */
|
|
6
|
+
export declare const PENDING_STATEMENT: string;
|
|
7
|
+
/** A value as reported: 128 bit integers and hashes are strings, so nothing is rounded. */
|
|
8
|
+
export type DecodedValue = string | boolean;
|
|
9
|
+
export type OutcomeState = "pending" | "idle" | "absent" | "unreadable";
|
|
10
|
+
export interface RuleOutcome {
|
|
11
|
+
readonly rule: string;
|
|
12
|
+
/**
|
|
13
|
+
* `pending`: the rule fired. `idle`: its keys are there and it did not fire. `absent`: none of
|
|
14
|
+
* its keys is in the instance storage. `unreadable`: a key is there but cannot be understood.
|
|
15
|
+
*/
|
|
16
|
+
readonly state: OutcomeState;
|
|
17
|
+
/** Why the state is `unreadable`, or why a firing rule was held back. Null otherwise. */
|
|
18
|
+
readonly reason: string | null;
|
|
19
|
+
/** The code hash the contract will run, from the rule's candidate key. Null when the rule has none or it is not set. */
|
|
20
|
+
readonly candidateHash: string | null;
|
|
21
|
+
/** Unix seconds, from the rule's deadline key. */
|
|
22
|
+
readonly deadline: number | null;
|
|
23
|
+
/** Deadline minus the ledger close time, in seconds: negative when the deadline has passed. Null when either is unknown. */
|
|
24
|
+
readonly secondsLeft: number | null;
|
|
25
|
+
/** True when the ledger close time is at or after the deadline. Null when either is unknown. */
|
|
26
|
+
readonly canBeAppliedNow: boolean | null;
|
|
27
|
+
/** The decoded value of every key of the rule that is in the storage, by key name. */
|
|
28
|
+
readonly values: Readonly<Record<string, DecodedValue>>;
|
|
29
|
+
}
|
|
30
|
+
export interface PendingState {
|
|
31
|
+
/** The close time of the latest ledger the RPC reported, in unix seconds. Null when it did not report one. */
|
|
32
|
+
readonly ledgerCloseTime: number | null;
|
|
33
|
+
readonly rules: readonly RuleOutcome[];
|
|
34
|
+
/** Things the reader should know: keys that are absent, a close time that could not be read. */
|
|
35
|
+
readonly notes: readonly string[];
|
|
36
|
+
/** Present when a rule fired. */
|
|
37
|
+
readonly statement?: string;
|
|
38
|
+
}
|
package/dist/rpc.d.ts
ADDED
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
/** The most keys one `getLedgerEntries` call may carry. */
|
|
2
|
+
export declare const MAX_KEYS_PER_CALL = 200;
|
|
3
|
+
/**
|
|
4
|
+
* Why the provider gave no usable answer. Every one of these means "could not tell", never "the
|
|
5
|
+
* ledger says no": the caller reports the affected contracts as incomplete.
|
|
6
|
+
*
|
|
7
|
+
* - `timeout`: no response within the per-request timeout.
|
|
8
|
+
* - `network`: the connection failed (also after the one retry).
|
|
9
|
+
* - `rate-limited`: HTTP 429 after the one retry, or a `Retry-After` longer than the bound.
|
|
10
|
+
* - `server-error`: HTTP 5xx.
|
|
11
|
+
* - `http-error`: any other non-2xx status (bad key, wrong path).
|
|
12
|
+
* - `malformed`: not JSON, not a JSON-RPC response, or a result of the wrong shape.
|
|
13
|
+
* - `rpc-error`: a JSON-RPC error object instead of a result.
|
|
14
|
+
*/
|
|
15
|
+
export type RpcFailureKind = "timeout" | "network" | "rate-limited" | "server-error" | "http-error" | "malformed" | "rpc-error";
|
|
16
|
+
/**
|
|
17
|
+
* The provider did not answer in a way that can be read. An answer that says "no such entry" is
|
|
18
|
+
* not an error: it is returned as data (an absent entry) and is the finding.
|
|
19
|
+
*/
|
|
20
|
+
export declare class RpcError extends Error {
|
|
21
|
+
readonly kind: RpcFailureKind;
|
|
22
|
+
constructor(kind: RpcFailureKind, message: string);
|
|
23
|
+
}
|
|
24
|
+
export interface NetworkInfo {
|
|
25
|
+
readonly passphrase: string;
|
|
26
|
+
}
|
|
27
|
+
export interface LatestLedger {
|
|
28
|
+
readonly sequence: number;
|
|
29
|
+
/** When the ledger closed, in unix seconds, when the provider says so. */
|
|
30
|
+
readonly closeTime?: number;
|
|
31
|
+
}
|
|
32
|
+
/** One ledger entry as the provider returned it, before any XDR decoding. */
|
|
33
|
+
export interface RawLedgerEntry {
|
|
34
|
+
/** The ledger key, base64 XDR, as returned by the provider. */
|
|
35
|
+
readonly key: string;
|
|
36
|
+
/** The ledger entry data, base64 XDR. */
|
|
37
|
+
readonly xdr: string;
|
|
38
|
+
readonly lastModifiedLedgerSeq: number;
|
|
39
|
+
/** Absent for entries without a TTL. */
|
|
40
|
+
readonly liveUntilLedgerSeq?: number;
|
|
41
|
+
}
|
|
42
|
+
export interface LedgerEntriesResult {
|
|
43
|
+
/** The latest ledger the provider had when it answered. */
|
|
44
|
+
readonly latestLedger: number;
|
|
45
|
+
readonly entries: readonly RawLedgerEntry[];
|
|
46
|
+
}
|
|
47
|
+
/** The ledgers the provider retains, as `getHealth` reports them. */
|
|
48
|
+
export interface Health {
|
|
49
|
+
readonly latestLedger: number;
|
|
50
|
+
/** The oldest ledger the provider still serves events and transactions for. */
|
|
51
|
+
readonly oldestLedger: number;
|
|
52
|
+
}
|
|
53
|
+
/** The most events one `getEvents` call may be asked for. */
|
|
54
|
+
export declare const MAX_EVENTS_PER_CALL = 10000;
|
|
55
|
+
/**
|
|
56
|
+
* One `getEvents` call: the system events of one contract whose topics match `topics` (base64
|
|
57
|
+
* ScVal each, or "*" for any one). The first call names a ledger to start at, a later one the
|
|
58
|
+
* cursor the previous answer gave.
|
|
59
|
+
*/
|
|
60
|
+
export interface EventsQuery {
|
|
61
|
+
readonly contractId: string;
|
|
62
|
+
readonly topics: readonly string[];
|
|
63
|
+
readonly limit: number;
|
|
64
|
+
readonly start: {
|
|
65
|
+
readonly startLedger: number;
|
|
66
|
+
} | {
|
|
67
|
+
readonly cursor: string;
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
/** One event as the provider returned it, before any XDR decoding. */
|
|
71
|
+
export interface RawEvent {
|
|
72
|
+
readonly type: string;
|
|
73
|
+
readonly ledger: number;
|
|
74
|
+
readonly ledgerClosedAt: string;
|
|
75
|
+
readonly contractId: string;
|
|
76
|
+
/** Sorts in ledger, transaction and event order. */
|
|
77
|
+
readonly id: string;
|
|
78
|
+
readonly operationIndex?: number;
|
|
79
|
+
readonly txHash: string;
|
|
80
|
+
/** Base64 ScVals. */
|
|
81
|
+
readonly topic: readonly string[];
|
|
82
|
+
readonly value: string;
|
|
83
|
+
}
|
|
84
|
+
export interface EventsPage {
|
|
85
|
+
readonly events: readonly RawEvent[];
|
|
86
|
+
/** Where the next call continues. The provider also sends one when a scan window ended. */
|
|
87
|
+
readonly cursor: string | null;
|
|
88
|
+
readonly latestLedger: number;
|
|
89
|
+
}
|
|
90
|
+
/** A transaction as `getTransaction` returned it. Only the parts the tool decodes. */
|
|
91
|
+
export interface RawTransaction {
|
|
92
|
+
readonly status: "SUCCESS" | "FAILED" | "NOT_FOUND";
|
|
93
|
+
readonly txHash?: string;
|
|
94
|
+
readonly ledger?: number;
|
|
95
|
+
/** Seconds since the epoch. */
|
|
96
|
+
readonly createdAt?: number;
|
|
97
|
+
/** Base64 XDR. Absent when the transaction was not found. */
|
|
98
|
+
readonly envelopeXdr?: string;
|
|
99
|
+
}
|
|
100
|
+
/** The read-only RPC surface. Tests inject a fake; production uses `createRpcTransport`. */
|
|
101
|
+
export interface RpcTransport {
|
|
102
|
+
getNetwork(): Promise<NetworkInfo>;
|
|
103
|
+
getLatestLedger(): Promise<LatestLedger>;
|
|
104
|
+
getHealth(): Promise<Health>;
|
|
105
|
+
/** At most `MAX_KEYS_PER_CALL` base64 ledger keys; use `readLedgerEntries` for more. */
|
|
106
|
+
getLedgerEntries(keys: readonly string[]): Promise<LedgerEntriesResult>;
|
|
107
|
+
getEvents(query: EventsQuery): Promise<EventsPage>;
|
|
108
|
+
getTransaction(hash: string): Promise<RawTransaction>;
|
|
109
|
+
}
|
|
110
|
+
/** The part of `fetch` the transport uses, so tests and the recorder can wrap it. */
|
|
111
|
+
export type FetchLike = (input: string, init: RequestInit) => Promise<Response>;
|
|
112
|
+
export interface TransportOptions {
|
|
113
|
+
readonly url: string;
|
|
114
|
+
/** Extra request headers, for providers that need an API key. Never logged. */
|
|
115
|
+
readonly headers?: Readonly<Record<string, string>>;
|
|
116
|
+
readonly timeoutMs?: number;
|
|
117
|
+
readonly fetch?: FetchLike;
|
|
118
|
+
/** Injected so tests do not wait. */
|
|
119
|
+
readonly sleep?: (ms: number) => Promise<void>;
|
|
120
|
+
/** Reads the clock, for `Retry-After` given as a date. */
|
|
121
|
+
readonly now?: () => number;
|
|
122
|
+
}
|
|
123
|
+
export declare const DEFAULT_TIMEOUT_MS = 10000;
|
|
124
|
+
/** The longest `Retry-After` the single retry will wait for. A longer one is not retried. */
|
|
125
|
+
export declare const MAX_RETRY_AFTER_MS = 10000;
|
|
126
|
+
/** The wait before the retry when the provider names none. */
|
|
127
|
+
export declare const DEFAULT_RETRY_WAIT_MS = 1000;
|
|
128
|
+
/** `Retry-After` as milliseconds from now: delta-seconds or an HTTP date. Undefined when unusable. */
|
|
129
|
+
export declare function parseRetryAfter(header: string | null, now: number): number | undefined;
|
|
130
|
+
/** A JSON-RPC over fetch implementation. One retry on 429 or a connection failure, nothing else. */
|
|
131
|
+
export declare function createRpcTransport(options: TransportOptions): RpcTransport;
|
|
132
|
+
/** One answered chunk of a batched read. */
|
|
133
|
+
export interface BatchOutcome {
|
|
134
|
+
readonly keys: readonly string[];
|
|
135
|
+
readonly result: LedgerEntriesResult | RpcError;
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Reads any number of keys with ceil(n / 200) calls, in order. A failed call does not abort the
|
|
139
|
+
* rest: its keys carry the error, so the caller can report only the affected contracts.
|
|
140
|
+
*/
|
|
141
|
+
export declare function readLedgerEntries(transport: RpcTransport, keys: readonly string[]): Promise<BatchOutcome[]>;
|
package/dist/rules.d.ts
ADDED
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pending-upgrade rules. A rule is data: it names instance storage keys to read, how to decode
|
|
3
|
+
* each one, which key is the candidate code hash, which is the deadline, and when the rule fires.
|
|
4
|
+
* There are no scripts, no expressions and no network targets in it, so a rules file can only
|
|
5
|
+
* change what is looked for in a contract's own instance storage, never what the tool does.
|
|
6
|
+
*
|
|
7
|
+
* Only INSTANCE storage is read in this version. Persistent and temporary storage are out of
|
|
8
|
+
* scope: they need one more ledger read per key, and no rule here can ask for one.
|
|
9
|
+
*/
|
|
10
|
+
export declare const RULES_FILE_NAME = "wasmlock.rules.json";
|
|
11
|
+
export declare const RULES_VERSION = 1;
|
|
12
|
+
export declare const MAX_RULES = 50;
|
|
13
|
+
export declare const MAX_KEYS_PER_RULE = 8;
|
|
14
|
+
export declare const MAX_KEY_PARTS = 8;
|
|
15
|
+
/** The most bytes a rules file may hold. */
|
|
16
|
+
export declare const MAX_RULES_FILE_BYTES = 65536;
|
|
17
|
+
export declare const MAX_DESCRIPTION_CHARS = 200;
|
|
18
|
+
export declare const RULE_NAME: RegExp;
|
|
19
|
+
/** What a value is decoded as. `hash` is 32 bytes, printed as lowercase hex; 128 bit integers are decimal strings. */
|
|
20
|
+
export declare const VALUE_TYPES: readonly ["u32", "u64", "i128", "u128", "bool", "address", "hash", "string", "symbol"];
|
|
21
|
+
export type ValueType = (typeof VALUE_TYPES)[number];
|
|
22
|
+
export type KeyPart = {
|
|
23
|
+
readonly kind: "symbol";
|
|
24
|
+
readonly value: string;
|
|
25
|
+
} | {
|
|
26
|
+
readonly kind: "u32";
|
|
27
|
+
readonly value: number;
|
|
28
|
+
} | {
|
|
29
|
+
readonly kind: "bool";
|
|
30
|
+
readonly value: boolean;
|
|
31
|
+
} | {
|
|
32
|
+
readonly kind: "address";
|
|
33
|
+
readonly value: string;
|
|
34
|
+
};
|
|
35
|
+
/**
|
|
36
|
+
* A storage key. A plain string in the rules file is a Soroban enum unit variant: an ScVal Vec of
|
|
37
|
+
* one Symbol (what `#[contracttype]` makes of `Key::Name`). `{ "symbol": "name" }` is a bare Symbol
|
|
38
|
+
* key and `{ "vec": [...] }` a Vec of simple parts.
|
|
39
|
+
*/
|
|
40
|
+
export type KeySpec = {
|
|
41
|
+
readonly kind: "symbol";
|
|
42
|
+
readonly name: string;
|
|
43
|
+
} | {
|
|
44
|
+
readonly kind: "vec";
|
|
45
|
+
readonly parts: readonly KeyPart[];
|
|
46
|
+
};
|
|
47
|
+
export interface KeyRead {
|
|
48
|
+
/** The name the rule refers to this key by, and the name its decoded value is reported under. */
|
|
49
|
+
readonly name: string;
|
|
50
|
+
readonly spec: KeySpec;
|
|
51
|
+
readonly type: ValueType;
|
|
52
|
+
/** A canonical text of `spec`: two keys match exactly when their fingerprints are equal. */
|
|
53
|
+
readonly fingerprint: string;
|
|
54
|
+
}
|
|
55
|
+
export type FireWhen = "nonzero" | "present";
|
|
56
|
+
export interface Rule {
|
|
57
|
+
readonly name: string;
|
|
58
|
+
readonly description?: string;
|
|
59
|
+
readonly keys: readonly KeyRead[];
|
|
60
|
+
/** The name of the key (a `hash`) that holds the code hash the contract will run. */
|
|
61
|
+
readonly candidate?: string;
|
|
62
|
+
/** The name of the key (a `u32` or `u64`) that holds the unix time, in seconds, the upgrade can be applied at. */
|
|
63
|
+
readonly deadline?: string;
|
|
64
|
+
readonly fires: {
|
|
65
|
+
readonly key: string;
|
|
66
|
+
readonly when: FireWhen;
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
export interface RulesIssue {
|
|
70
|
+
readonly path: string;
|
|
71
|
+
readonly message: string;
|
|
72
|
+
}
|
|
73
|
+
export declare class RulesError extends Error {
|
|
74
|
+
readonly issues: readonly RulesIssue[];
|
|
75
|
+
constructor(issues: readonly RulesIssue[], source?: string);
|
|
76
|
+
}
|
|
77
|
+
/** The fingerprint of a key part, the same text for a rule's part and for the ledger's ScVal. */
|
|
78
|
+
export declare function partFingerprint(part: KeyPart): string;
|
|
79
|
+
export declare function specFingerprint(spec: KeySpec): string;
|
|
80
|
+
export declare class Issues {
|
|
81
|
+
readonly list: RulesIssue[];
|
|
82
|
+
add(path: string, message: string): void;
|
|
83
|
+
/** Rejects keys outside the format, so a typo never silently drops a field. */
|
|
84
|
+
keys(path: string, obj: Record<string, unknown>, required: readonly string[], optional: readonly string[]): void;
|
|
85
|
+
}
|
|
86
|
+
/** Validates one rule. Pushes every problem found to `issues`; returns the rule only when there is none. */
|
|
87
|
+
export declare function readRule(issues: Issues, path: string, value: unknown): Rule | undefined;
|
|
88
|
+
/** Validates an already-parsed rules file. Throws {@link RulesError} listing every problem found. */
|
|
89
|
+
export declare function validateRules(value: unknown, source?: string): readonly Rule[];
|
|
90
|
+
/** Parses rules file text: rejects invalid JSON, repeated keys and anything outside the format. */
|
|
91
|
+
export declare function parseRules(text: string, source?: string): readonly Rule[];
|
|
92
|
+
/** The built-in presets, as data, written in the rules file format and validated by the same code. */
|
|
93
|
+
export declare const PRESET_DATA: readonly unknown[];
|
|
94
|
+
export declare const PRESETS: ReadonlyMap<string, Rule>;
|
|
95
|
+
/**
|
|
96
|
+
* The rules the lockfile names, resolved against the presets and the user rules. Throws
|
|
97
|
+
* `ConfigError` (a usage error) naming the first name that resolves to neither. Called before any
|
|
98
|
+
* network read.
|
|
99
|
+
*/
|
|
100
|
+
export declare function resolveRules(contracts: readonly {
|
|
101
|
+
readonly id: string;
|
|
102
|
+
readonly pending?: readonly string[];
|
|
103
|
+
}[], userRules: readonly Rule[]): ReadonlyMap<string, Rule>;
|
|
104
|
+
/**
|
|
105
|
+
* Loads the user rules: the file `--rules` names, else `wasmlock.rules.json` next to the lockfile
|
|
106
|
+
* when it exists, else none. A file named by `--rules` must exist. The path is never read from the
|
|
107
|
+
* lockfile.
|
|
108
|
+
*/
|
|
109
|
+
export declare function loadRules(lockfilePath: string, rulesFlag: string | undefined): readonly Rule[];
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The normalized interface of a contract: what the lockfile stores under `interface.snapshot`.
|
|
3
|
+
* Every type is a canonical type string (see `typestring.ts`). Doc strings are not part of the
|
|
4
|
+
* interface and are never stored. The lists are sorted by name; the order inside an item is the
|
|
5
|
+
* order of the spec, because it is meaningful there (function arguments, tuple-struct fields,
|
|
6
|
+
* enum cases).
|
|
7
|
+
*/
|
|
8
|
+
/** A named, typed slot: a function argument, a struct field or an event parameter. */
|
|
9
|
+
export interface Param {
|
|
10
|
+
readonly name: string;
|
|
11
|
+
readonly type: string;
|
|
12
|
+
}
|
|
13
|
+
export interface FunctionItem {
|
|
14
|
+
readonly name: string;
|
|
15
|
+
/** Arguments in call order. */
|
|
16
|
+
readonly inputs: readonly Param[];
|
|
17
|
+
/** Zero or one type; an empty list is a function that returns nothing. */
|
|
18
|
+
readonly outputs: readonly string[];
|
|
19
|
+
}
|
|
20
|
+
export interface StructItem {
|
|
21
|
+
readonly name: string;
|
|
22
|
+
readonly kind: "struct";
|
|
23
|
+
/** Only present when the spec entry names a library. */
|
|
24
|
+
readonly lib?: string;
|
|
25
|
+
readonly fields: readonly Param[];
|
|
26
|
+
}
|
|
27
|
+
export interface UnionCase {
|
|
28
|
+
readonly name: string;
|
|
29
|
+
/** The payload types; empty for a case without payload. */
|
|
30
|
+
readonly types: readonly string[];
|
|
31
|
+
}
|
|
32
|
+
export interface UnionItem {
|
|
33
|
+
readonly name: string;
|
|
34
|
+
readonly kind: "union";
|
|
35
|
+
readonly lib?: string;
|
|
36
|
+
readonly cases: readonly UnionCase[];
|
|
37
|
+
}
|
|
38
|
+
export interface EnumCase {
|
|
39
|
+
readonly name: string;
|
|
40
|
+
readonly value: number;
|
|
41
|
+
}
|
|
42
|
+
export interface EnumItem {
|
|
43
|
+
readonly name: string;
|
|
44
|
+
readonly kind: "enum";
|
|
45
|
+
readonly lib?: string;
|
|
46
|
+
readonly cases: readonly EnumCase[];
|
|
47
|
+
}
|
|
48
|
+
export type TypeItem = StructItem | UnionItem | EnumItem;
|
|
49
|
+
/** An error enum: the `contracterror` codes a contract can fail with. */
|
|
50
|
+
export interface ErrorItem {
|
|
51
|
+
readonly name: string;
|
|
52
|
+
readonly lib?: string;
|
|
53
|
+
readonly cases: readonly EnumCase[];
|
|
54
|
+
}
|
|
55
|
+
export type EventLocation = "topic" | "data";
|
|
56
|
+
export type EventDataFormat = "single-value" | "vec" | "map";
|
|
57
|
+
export interface EventParam {
|
|
58
|
+
readonly name: string;
|
|
59
|
+
readonly type: string;
|
|
60
|
+
readonly location: EventLocation;
|
|
61
|
+
}
|
|
62
|
+
export interface EventItem {
|
|
63
|
+
readonly name: string;
|
|
64
|
+
readonly lib?: string;
|
|
65
|
+
/** The fixed leading topics, such as the event name. */
|
|
66
|
+
readonly prefixTopics: readonly string[];
|
|
67
|
+
readonly dataFormat: EventDataFormat;
|
|
68
|
+
readonly params: readonly EventParam[];
|
|
69
|
+
}
|
|
70
|
+
export interface Snapshot {
|
|
71
|
+
readonly functions: readonly FunctionItem[];
|
|
72
|
+
readonly types: readonly TypeItem[];
|
|
73
|
+
readonly errors: readonly ErrorItem[];
|
|
74
|
+
readonly events: readonly EventItem[];
|
|
75
|
+
}
|
|
76
|
+
export declare const SNAPSHOT_KEYS: readonly ["functions", "types", "errors", "events"];
|
|
77
|
+
/** Code unit order, never locale order, so the result is the same everywhere. */
|
|
78
|
+
export declare function compareNames(a: string, b: string): number;
|
|
79
|
+
/** The snapshot with every list sorted by name. The digest is taken over this form. */
|
|
80
|
+
export declare function sortSnapshot(snapshot: Snapshot): Snapshot;
|
|
81
|
+
/**
|
|
82
|
+
* `sha256:` plus the hex digest of the canonical JSON text of the snapshot (sorted keys, two-space
|
|
83
|
+
* indent, trailing newline), with the lists sorted by name. Reordering items does not change it;
|
|
84
|
+
* changing any type string, name, code or field does.
|
|
85
|
+
*/
|
|
86
|
+
export declare function interfaceDigest(snapshot: Snapshot): string;
|
|
87
|
+
/** The user-defined type names a function signature refers to. */
|
|
88
|
+
export declare function functionRefs(fn: FunctionItem): string[];
|
|
89
|
+
/** The user-defined type names a type or error item refers to. */
|
|
90
|
+
export declare function typeItemRefs(item: TypeItem): string[];
|
|
91
|
+
/**
|
|
92
|
+
* Every type or error name reachable from the signatures of the named functions, through the type
|
|
93
|
+
* graph (struct fields, union payloads). A name that no item defines is kept in the result as a
|
|
94
|
+
* dangling reference. Cycles terminate: each name is visited once.
|
|
95
|
+
*/
|
|
96
|
+
export declare function reachableFrom(snapshot: Snapshot, functionNames: ReadonlySet<string>): Set<string>;
|
package/dist/spec.d.ts
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { type Snapshot } from "./snapshot.ts";
|
|
2
|
+
import { type ImportRef } from "./wasm.ts";
|
|
3
|
+
import { type MetaEntry } from "./lockfile.ts";
|
|
4
|
+
/** The spec or meta bytes do not decode, or do not describe a coherent interface. */
|
|
5
|
+
export declare class SpecError extends Error {
|
|
6
|
+
constructor(message: string);
|
|
7
|
+
}
|
|
8
|
+
export declare const SPEC_SECTION = "contractspecv0";
|
|
9
|
+
export declare const META_SECTION = "contractmetav0";
|
|
10
|
+
/** Everything the lockfile and the diff read from a module's bytes. */
|
|
11
|
+
export interface WasmInterface {
|
|
12
|
+
readonly snapshot: Snapshot;
|
|
13
|
+
/** `sha256:` digest of the snapshot, as the lockfile stores it. */
|
|
14
|
+
readonly digest: string;
|
|
15
|
+
readonly meta: readonly MetaEntry[];
|
|
16
|
+
/** Host imports, sorted by module then name. */
|
|
17
|
+
readonly imports: readonly ImportRef[];
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* The interface of a module: parses the sections, decodes and normalizes the spec and the meta.
|
|
21
|
+
* A module with more than one `contractspecv0` (or `contractmetav0`) section has them concatenated
|
|
22
|
+
* in file order before decoding. Throws `WasmError` or `SpecError`; a module without a
|
|
23
|
+
* `contractspecv0` section is a `SpecError`, because "no spec" must never read as "no interface".
|
|
24
|
+
*/
|
|
25
|
+
export declare function snapshotFromWasm(bytes: Uint8Array): WasmInterface;
|
package/dist/strkey.d.ts
ADDED