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.
@@ -0,0 +1,22 @@
1
+ /**
2
+ * The canonical type strings of the interface snapshot, and their grammar.
3
+ *
4
+ * type := primitive | Option<type> | Result<type,type> | Vec<type> | Map<type,type>
5
+ * | BytesN<digits> | "(" [type {"," type}] ["," if one element] ")" | UdtName
6
+ *
7
+ * There is no whitespace anywhere. A user-defined type is its bare name, so the strings keep the
8
+ * references that reachability needs. A UDT whose name collides with a builtin keyword cannot be
9
+ * told apart, so it is not representable (the spec decoder refuses it).
10
+ */
11
+ export declare const PRIMITIVES: ReadonlySet<string>;
12
+ export declare const UDT_NAME: RegExp;
13
+ /** Nesting deeper than this is refused: no real signature comes close, and it bounds recursion. */
14
+ export declare const MAX_TYPE_DEPTH = 32;
15
+ export declare function isReservedTypeName(name: string): boolean;
16
+ export declare class TypeStringError extends Error {
17
+ constructor(message: string);
18
+ }
19
+ /** The user-defined type names a type string refers to, sorted. Throws on a malformed string. */
20
+ export declare function typeRefs(text: string): string[];
21
+ /** Whether the text is a well-formed canonical type string. */
22
+ export declare function isTypeString(text: string): boolean;
@@ -0,0 +1,91 @@
1
+ /**
2
+ * Untrusted text.
3
+ *
4
+ * The code of a contract is controlled by whoever administers it, and a contract that is pinned
5
+ * here can be upgraded to any Wasm. Every string read from that code (meta keys and values, names
6
+ * in the spec, host import names, event data) and every string an RPC provider chooses (error
7
+ * messages, event ids) is therefore attacker-controlled. The reports this tool writes are read in
8
+ * terminals and CI logs and are pasted as pull request bodies.
9
+ *
10
+ * Policy: text a contract or an RPC provider controls is shown only as inert code in markdown and
11
+ * as escaped printable text in a terminal. Nothing it can write is ever interpreted as markdown,
12
+ * HTML, a mention, a link, an image or a control sequence.
13
+ *
14
+ * - {@link forTerminal}: every control character (C0, DEL, C1, so ESC, CR, NUL and the rest),
15
+ * bidirectional controls, zero-width and other invisible or format characters, line and
16
+ * paragraph separators, spaces other than U+0020, private-use and unassigned code points and
17
+ * lone surrogates is written as a visible escape such as `\u{202e}`. A literal backslash is
18
+ * written `\\`, so the output reads back unambiguously and an input cannot forge an escape.
19
+ * - {@link forMarkdown}: the same escaping, then the text is written ONLY inside an inline code
20
+ * span whose backtick fence is longer than any backtick run inside the text, padded with one
21
+ * space on each side when the text starts or ends with a backtick. A pipe is written `\|`, which
22
+ * a table cell reads back as `|` (GitHub requires the escape even inside a code span). The result
23
+ * holds no newline.
24
+ * - Both keep at most `max` code points and end with a visible marker that says how many were
25
+ * dropped, so the length of the output is bounded (each kept code point becomes at most 10
26
+ * characters).
27
+ *
28
+ * Neutralization happens where text is rendered, never in the data: results and `--json` keep the
29
+ * exact original strings. Both renderers are single passes: no step is quadratic in the input and
30
+ * no regular expression nests a quantifier.
31
+ */
32
+ /** The most code points a renderer keeps by default. Meta values are stored at most 1,024 long. */
33
+ export declare const DEFAULT_MAX = 2048;
34
+ /** The longest text of an escape: `\u{10ffff}`. */
35
+ export declare const MAX_ESCAPE_LENGTH = 10;
36
+ /** The number of code points in a string. A lone surrogate counts as one. */
37
+ export declare function codePointLength(text: string): number;
38
+ /** The text of the marker that says how many characters were dropped. */
39
+ export declare const truncationMarker: (dropped: number) => string;
40
+ /** The longest {@link truncationMarker} the tool writes, with room to spare. */
41
+ export declare const MARKER_ALLOWANCE = 48;
42
+ /**
43
+ * For data that is stored: the first `max` code points of `text`, followed by the visible marker
44
+ * when something was dropped. Nothing else is changed, so the result is still the contract's own
45
+ * text.
46
+ */
47
+ export declare function clip(text: string, max: number): string;
48
+ /** Text for a terminal or a log: printable, with every control or invisible character written as an escape. */
49
+ export declare function forTerminal(text: string, max?: number): string;
50
+ /**
51
+ * {@link forTerminal} for a message of several lines that this tool wrote around values it did not
52
+ * control (an error message, a list of reasons): each line is neutralized, the line breaks are kept.
53
+ */
54
+ export declare function linesForTerminal(text: string, max?: number): string;
55
+ /** Text for markdown: one inline code span, which GitHub renders with no mention, link, image or HTML. */
56
+ export declare function forMarkdown(text: string, max?: number): string;
57
+ /** A piece of a message: fixed words written by this tool, or text a contract or a provider controls. */
58
+ export interface Part {
59
+ readonly text: string;
60
+ readonly untrusted: boolean;
61
+ }
62
+ export type Message = readonly Part[];
63
+ export declare const trusted: (text: string) => Part;
64
+ export declare const untrusted: (text: string) => Part;
65
+ type Slot = Part | Message | number;
66
+ /**
67
+ * Builds a message from a template. The literal parts of the template are fixed words; every value
68
+ * must be a {@link Part}, a nested message or a number, so a string cannot be interpolated by
69
+ * accident: it has to be marked {@link untrusted} or {@link trusted} on purpose.
70
+ */
71
+ export declare function msg(strings: TemplateStringsArray, ...slots: readonly Slot[]): Message;
72
+ /** Joins messages with a fixed separator. */
73
+ export declare function joinMessages(items: readonly Message[], separator: string): Message;
74
+ export declare const plain: (message: Message) => string;
75
+ /** The plain text of a message, remembering which spans of it are untrusted. */
76
+ export declare function compose(message: Message): string;
77
+ /** Whether {@link compose} produced this text. */
78
+ export declare const isComposed: (text: string) => boolean;
79
+ /**
80
+ * A message that was built here ({@link compose}), rendered for a terminal. A text that was not
81
+ * built from parts is shown as it is: it holds fixed words only. Use {@link messageForTerminal} for
82
+ * a text that must have been built from parts.
83
+ */
84
+ export declare function textForTerminal(text: string): string;
85
+ /** The same as {@link textForTerminal}, for markdown (a line or a table cell). */
86
+ export declare function textForMarkdown(text: string): string;
87
+ /** Like {@link textForTerminal}, but a text that was not built from parts is wholly untrusted. */
88
+ export declare function messageForTerminal(text: string): string;
89
+ /** Like {@link textForMarkdown}, but a text that was not built from parts is wholly untrusted. */
90
+ export declare function messageForMarkdown(text: string): string;
91
+ export {};
@@ -0,0 +1,14 @@
1
+ import type { UpdateReport } from "./update.ts";
2
+ /**
3
+ * The markdown report and the console summary of `update`. Whatever a contract, a lockfile edit or
4
+ * an RPC provider controls (labels, reasons, notes, tags, function names, event ids) is written
5
+ * through the renderers of `src/untrusted.ts`: inert code in markdown, escaped printable text in a
6
+ * terminal. The fixed words, hashes, ledger numbers and strkey addresses are written as they are.
7
+ */
8
+ export type UpdateFormat = "text" | "json";
9
+ export declare function isUpdateFormat(value: string): value is UpdateFormat;
10
+ /** The report a person pastes into a pull request. The order of the sections is fixed. */
11
+ export declare function formatUpdateMarkdown(report: UpdateReport): string;
12
+ export declare function formatUpdateJson(report: UpdateReport): string;
13
+ /** The console summary. */
14
+ export declare function formatUpdateText(report: UpdateReport): string;
@@ -0,0 +1,82 @@
1
+ import { type ReachState } from "./check.ts";
2
+ import { type DiffReport } from "./diff.ts";
3
+ import type { ContractEntry, Lockfile, Reach } from "./lockfile.ts";
4
+ import type { Network } from "./network.ts";
5
+ import { type RpcTransport } from "./rpc.ts";
6
+ import type { Rule } from "./rules.ts";
7
+ import { type UpgradeLocation } from "./upgrade.ts";
8
+ /** Printed first in every report: the tool proposes, a person decides. */
9
+ export declare const PROPOSAL_STATEMENT = "wasmlock proposes this change to the lockfile and a person decides whether to accept it. It does not say the new code is safe.";
10
+ export type UpdateOutcome = "updated" | "unchanged" | "not-updated";
11
+ /** The fields of a pin that a re-pin rewrites. */
12
+ export interface PinSummary {
13
+ readonly wasmHash: string;
14
+ readonly reach: Reach;
15
+ readonly codeLedgerHint: number;
16
+ readonly instanceLedgerHint: number;
17
+ readonly pinnedAt: number;
18
+ readonly interfaceDigest: string;
19
+ /** True when the entry holds the full snapshot, false when only the digest. */
20
+ readonly snapshot: boolean;
21
+ readonly metaEntries: number;
22
+ readonly imports: number;
23
+ }
24
+ export interface UpdateItem {
25
+ readonly id: string;
26
+ readonly label: string | null;
27
+ readonly outcome: UpdateOutcome;
28
+ /** Why a contract was not updated. Empty otherwise. */
29
+ readonly reasons: readonly string[];
30
+ /** The ledger's state against the pin, as `check` reads it. */
31
+ readonly live: {
32
+ readonly reach: ReachState;
33
+ readonly wasmHash: string | null;
34
+ } | null;
35
+ readonly before: PinSummary;
36
+ /** The pin as rewritten. Null unless the contract was updated. */
37
+ readonly after: PinSummary | null;
38
+ /** The classifier's report for the change. Null unless the contract was updated. */
39
+ readonly diff: DiffReport | null;
40
+ /** Why a contract was left as it is although its pin still holds: an upgrade is pending. Only set then. */
41
+ readonly note?: string;
42
+ /** True when the classifier found a breaking or potentially breaking interface change. */
43
+ readonly flagged: boolean;
44
+ readonly location: UpgradeLocation | null;
45
+ }
46
+ export interface UpdateReport {
47
+ readonly version: 1;
48
+ readonly network: Network;
49
+ /** The latest ledger any answer was taken at. Null when nothing was answered. */
50
+ readonly ledger: number | null;
51
+ readonly dryRun: boolean;
52
+ readonly summary: {
53
+ readonly total: number;
54
+ readonly updated: number;
55
+ readonly unchanged: number;
56
+ readonly notUpdated: number;
57
+ readonly flagged: number;
58
+ };
59
+ readonly statement: string;
60
+ readonly scope: string;
61
+ /** 0 when nothing could not be updated, 3 otherwise. Never 1: the pull request decides. */
62
+ readonly exitCode: 0 | 3;
63
+ readonly contracts: readonly UpdateItem[];
64
+ }
65
+ export declare function summarizePin(entry: ContractEntry): PinSummary;
66
+ export interface UpdatePlan {
67
+ readonly report: UpdateReport;
68
+ /** The lockfile with every updated entry rewritten, validated. Equal in content to the input when nothing was updated. */
69
+ readonly lockfile: Lockfile;
70
+ }
71
+ /**
72
+ * Reads the ledger for the named contracts (all when none is named), and for each one that
73
+ * drifted locates the upgrade, classifies the interface change and builds the re-pinned entry. It
74
+ * writes nothing: the caller writes the lockfile and the report. Never accepts a hash it did not
75
+ * read from the ledger.
76
+ *
77
+ * Throws `ConfigError` for an id the lockfile does not hold, `UsesError` when a contract's `uses`
78
+ * names a function its pinned interface lacks, and `NetworkMismatchError` for an endpoint of
79
+ * another network (all usage errors, nothing is written for any of them). A contract that cannot
80
+ * be read completely is reported as not updated.
81
+ */
82
+ export declare function planUpdate(lockfile: Lockfile, ids: readonly string[] | undefined, transport: RpcTransport, dryRun: boolean, userRules?: readonly Rule[]): Promise<UpdatePlan>;
@@ -0,0 +1,227 @@
1
+ import type { ContractResult } from "./check.ts";
2
+ import type { ContractEntry } from "./lockfile.ts";
3
+ import { type Network } from "./network.ts";
4
+ import { type RawEvent, type RpcTransport } from "./rpc.ts";
5
+ /**
6
+ * Finds the transaction that upgraded a contract, using only the RPC, and reads who authorized it.
7
+ * Everything here is read-only. Nothing is guessed: when no event matches, the location is
8
+ * unavailable and says why.
9
+ *
10
+ * Bounds, because contract events and transactions are attacker-controlled data:
11
+ * - the scan makes at most {@link MAX_EVENT_PAGES} calls of {@link EVENTS_PER_PAGE} events;
12
+ * - the events are walked once, never nested or copied inside a loop;
13
+ * - at most {@link MAX_AUTH_LISTED} authorizing addresses are listed, plus the two source accounts,
14
+ * so at most {@link MAX_AUTH_LISTED} + 2 accounts are read, in one call; the rest are only counted.
15
+ */
16
+ export declare const UPGRADE_TOPIC = "executable_update";
17
+ export declare const EVENTS_PER_PAGE = 200;
18
+ /** The provider scans 10000 ledgers per call, so a 7 day window (about 121000 ledgers) needs 13. */
19
+ export declare const MAX_EVENT_PAGES = 60;
20
+ export declare const MAX_AUTH_LISTED = 100;
21
+ export declare const MAX_SIGNATURES_LISTED = 20;
22
+ /** Printed with every signer list: the accounts are read when the tool runs, not at the upgrade. */
23
+ export declare const AS_OF_NOTE = "as of the check, not as of the upgrade ledger: signers and thresholds may have changed since";
24
+ /** Printed with every transaction: the tool does not follow the call tree. */
25
+ export declare const NESTING_NOTE = "the nested call path is not reconstructed: only the event's contract id identifies what changed, because an upgrade can be nested several contracts deep below the function the transaction invoked";
26
+ export declare const NO_EVENT_NOTE = "no upgrade event exists for this kind of change: the owner's tag entry was repointed, which emits no event on the referencing contract";
27
+ /** An executable named in an upgrade event. `hash` is set for the `Wasm` form only. */
28
+ export interface ExecutableRef {
29
+ readonly kind: string;
30
+ readonly hash: string | null;
31
+ }
32
+ export interface UpgradeEvent {
33
+ readonly id: string;
34
+ readonly ledger: number;
35
+ readonly closedAt: string;
36
+ readonly txHash: string;
37
+ readonly operationIndex: number | null;
38
+ readonly from: ExecutableRef;
39
+ readonly to: ExecutableRef;
40
+ }
41
+ export interface ScanInfo {
42
+ /** The first ledger scanned: the oldest the provider retains. */
43
+ readonly fromLedger: number;
44
+ readonly latestLedger: number;
45
+ readonly pages: number;
46
+ readonly pageCap: number;
47
+ /** Events the provider returned. */
48
+ readonly eventsSeen: number;
49
+ /** Returned events that were not a well formed upgrade of this contract. */
50
+ readonly ignored: number;
51
+ /** False when the page cap stopped the scan before the latest ledger. */
52
+ readonly complete: boolean;
53
+ }
54
+ export interface Hints {
55
+ readonly instanceLedgerHint: number;
56
+ readonly codeLedgerHint: number;
57
+ }
58
+ export interface AuthAddress {
59
+ readonly address: string;
60
+ readonly kind: "account" | "contract" | "other";
61
+ /** How many authorization entries carry this address. */
62
+ readonly entries: number;
63
+ }
64
+ export interface SignatureInfo {
65
+ readonly count: number;
66
+ /** The first four bytes of each signing key, hex, up to {@link MAX_SIGNATURES_LISTED}. */
67
+ readonly hints: readonly string[];
68
+ }
69
+ export type HostFunctionInfo = {
70
+ readonly kind: "invoke-contract";
71
+ readonly contractId: string;
72
+ readonly functionName: string;
73
+ } | {
74
+ readonly kind: "other";
75
+ readonly type: string;
76
+ };
77
+ export interface TransactionInfo {
78
+ readonly status: "found";
79
+ readonly hash: string;
80
+ readonly ledger: number;
81
+ /** ISO 8601, or null when the provider did not say. */
82
+ readonly createdAt: string | null;
83
+ /** Set for a fee bump: who paid, and the outer signatures. The upgrade's authority is below it. */
84
+ readonly feeBump: {
85
+ readonly feeSource: string;
86
+ readonly signatures: SignatureInfo;
87
+ } | null;
88
+ /** The transaction source account. */
89
+ readonly source: string;
90
+ readonly operationIndex: number;
91
+ readonly operationCount: number;
92
+ readonly operationSource: string | null;
93
+ readonly hostFunction: HostFunctionInfo;
94
+ readonly auth: {
95
+ readonly total: number;
96
+ /** Entries that rely on the transaction source account's signature. */
97
+ readonly sourceAccount: number;
98
+ /** Entries of other credentials, grouped by address; the first {@link MAX_AUTH_LISTED}. */
99
+ readonly addresses: readonly AuthAddress[];
100
+ readonly addressesOmitted: number;
101
+ };
102
+ readonly signatures: SignatureInfo;
103
+ readonly nesting: string;
104
+ }
105
+ export type TransactionState = TransactionInfo | {
106
+ readonly status: "unavailable";
107
+ readonly reason: string;
108
+ };
109
+ export interface Signer {
110
+ readonly key: string;
111
+ readonly weight: number;
112
+ }
113
+ export type AccountState = {
114
+ readonly status: "found";
115
+ readonly address: string;
116
+ readonly roles: readonly string[];
117
+ readonly readAtLedger: number;
118
+ readonly lastModifiedLedgerSeq: number;
119
+ readonly thresholds: {
120
+ readonly master: number;
121
+ readonly low: number;
122
+ readonly medium: number;
123
+ readonly high: number;
124
+ };
125
+ readonly signers: readonly Signer[];
126
+ } | {
127
+ readonly status: "absent";
128
+ readonly address: string;
129
+ readonly roles: readonly string[];
130
+ readonly readAtLedger: number;
131
+ } | {
132
+ readonly status: "unreadable";
133
+ readonly address: string;
134
+ readonly roles: readonly string[];
135
+ readonly reason: string;
136
+ };
137
+ export interface Authorizers {
138
+ readonly asOf: string;
139
+ readonly accounts: readonly AccountState[];
140
+ /** Contract addresses in the authorization entries: listed, not read. */
141
+ readonly contracts: readonly string[];
142
+ /** Authorizing addresses that were not read: those beyond the {@link MAX_AUTH_LISTED} listed. */
143
+ readonly addressesNotRead: number;
144
+ }
145
+ export interface FoundLocation {
146
+ readonly status: "found";
147
+ readonly hints: Hints;
148
+ readonly scan: ScanInfo;
149
+ /** The upgrade event that made the live code current. */
150
+ readonly event: UpgradeEvent;
151
+ /** Every upgrade from the pinned code to the live code that left an event, in ledger order. */
152
+ readonly chain: readonly UpgradeEvent[];
153
+ /** True when the chain leads back to the pinned hash; null when the pin was not a Wasm hash. */
154
+ readonly pinReached: boolean | null;
155
+ /** True when the chain holds more than one upgrade: the pin skipped intermediate versions. */
156
+ readonly skippedIntermediate: boolean;
157
+ readonly transaction: TransactionState;
158
+ readonly authorizers: Authorizers | null;
159
+ }
160
+ export interface NoEventLocation {
161
+ readonly status: "no-event";
162
+ readonly reason: string;
163
+ readonly hints: Hints;
164
+ /** `lastModifiedLedgerSeq` of the owner's tag entry, where the repoint happened. */
165
+ readonly ownerEntryLedger: number | null;
166
+ }
167
+ export interface UnavailableLocation {
168
+ readonly status: "unavailable";
169
+ readonly reason: string;
170
+ readonly hints: Hints;
171
+ readonly scan: ScanInfo | null;
172
+ }
173
+ export type UpgradeLocation = FoundLocation | NoEventLocation | UnavailableLocation;
174
+ /** An `executable_update` event of this contract, decoded; null for anything else. Never throws. */
175
+ export declare function parseUpgradeEvent(raw: RawEvent, contractId: string): UpgradeEvent | null;
176
+ /** The ledger a provider cursor points into: the ledger is the high 32 bits of the first number. */
177
+ export declare function cursorLedger(cursor: string): number;
178
+ /**
179
+ * Scans every retained ledger for the contract's upgrade events, oldest first, with at most
180
+ * {@link MAX_EVENT_PAGES} calls. Throws `RpcError` when the provider cannot be read.
181
+ */
182
+ export declare function scanUpgradeEvents(transport: RpcTransport, contractId: string): Promise<{
183
+ readonly events: readonly UpgradeEvent[];
184
+ readonly scan: ScanInfo;
185
+ }>;
186
+ export interface Chain {
187
+ /** In ledger order; the last one made the live code current. */
188
+ readonly events: readonly UpgradeEvent[];
189
+ readonly pinReached: boolean | null;
190
+ }
191
+ /**
192
+ * The upgrades that lead from the pinned code to the live code. Starts at the last event whose new
193
+ * executable is the live hash and walks the events once, backwards, following each event's old
194
+ * executable to the event that produced it, until it reaches the pinned hash. `pinnedHash` is
195
+ * null when the pin was not a Wasm hash (the old side of the first event cannot be compared).
196
+ * Returns null when no event upgrades to the live hash.
197
+ */
198
+ export declare function buildChain(events: readonly UpgradeEvent[], liveHash: string, pinnedHash: string | null): Chain | null;
199
+ /**
200
+ * Reads the upgrade transaction out of a `getTransaction` answer. The envelope is hashed and must
201
+ * hash to the event's transaction hash: an answer for another transaction is never reported.
202
+ */
203
+ export declare function decodeTransaction(raw: {
204
+ readonly status: string;
205
+ readonly txHash?: string;
206
+ readonly ledger?: number;
207
+ readonly createdAt?: number;
208
+ readonly envelopeXdr?: string;
209
+ }, event: UpgradeEvent, network: Network): TransactionState;
210
+ export declare function accountKey(address: string): string;
211
+ /**
212
+ * The classic accounts that authorized the transaction (its source, the operation source and the
213
+ * addresses of its authorization entries) read from the ledger now, with their thresholds and
214
+ * signers. Throws `RpcError` when the provider cannot be read.
215
+ */
216
+ export declare function readAuthorizers(transport: RpcTransport, info: TransactionInfo): Promise<Authorizers>;
217
+ export interface LocateInput {
218
+ readonly network: Network;
219
+ readonly entry: ContractEntry;
220
+ /** The check result of a drifted contract whose live code is known. */
221
+ readonly result: ContractResult;
222
+ }
223
+ /**
224
+ * Finds the upgrade of a drifted contract. Throws `RpcError` when the provider cannot be read (the
225
+ * contract is then reported incomplete). Everything else, including "not found", is a location.
226
+ */
227
+ export declare function locateUpgrade(transport: RpcTransport, input: LocateInput): Promise<UpgradeLocation>;
@@ -0,0 +1,2 @@
1
+ /** The version of this package, read from `package.json` when the bundle is built, so it cannot drift from it. */
2
+ export declare const VERSION: string;
package/dist/wasm.d.ts ADDED
@@ -0,0 +1,40 @@
1
+ /**
2
+ * A small, defensive reader for the parts of a Wasm module the interface diff needs: the custom
3
+ * sections by name and the import list. It reads bytes that come from a ledger and are hostile
4
+ * until proven otherwise, so every read is bounds checked and every failure is a {@link WasmError}.
5
+ * It never executes, validates or compiles the module.
6
+ */
7
+ /**
8
+ * The largest module accepted. Contract code is far below 1 MiB (the Aquarius router is about
9
+ * 50 KB), so the cap leaves a wide margin while bounding the work a hostile entry can cause.
10
+ */
11
+ export declare const MAX_WASM_BYTES: number;
12
+ /** The module cannot be read as Wasm. Always a typed error, never a stray exception. */
13
+ export declare class WasmError extends Error {
14
+ constructor(message: string);
15
+ }
16
+ export interface ImportRef {
17
+ readonly module: string;
18
+ readonly name: string;
19
+ }
20
+ /** One section as it sits in the module: its id, and where its payload starts and ends. */
21
+ export interface SectionSpan {
22
+ readonly id: number;
23
+ /** Offset of the section id byte. */
24
+ readonly start: number;
25
+ /** Offset of the first payload byte. */
26
+ readonly payloadStart: number;
27
+ /** Offset one past the last payload byte. */
28
+ readonly end: number;
29
+ }
30
+ export interface WasmSections {
31
+ /** Custom sections by name. A name that appears more than once keeps every body, in order. */
32
+ readonly customSections: ReadonlyMap<string, readonly Uint8Array[]>;
33
+ readonly imports: readonly ImportRef[];
34
+ }
35
+ /** Where every section sits. Throws on a truncated section or one that runs past the end. */
36
+ export declare function scanSections(bytes: Uint8Array): SectionSpan[];
37
+ /** Reads the custom sections and the import list. Throws {@link WasmError} on anything malformed. */
38
+ export declare function parseWasm(bytes: Uint8Array): WasmSections;
39
+ /** The custom section name of a span, or undefined for another kind of section. */
40
+ export declare function customSectionName(bytes: Uint8Array, span: SectionSpan): string | undefined;
package/package.json CHANGED
@@ -1,6 +1,50 @@
1
1
  {
2
2
  "name": "wasmlock",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.0",
4
+ "description": "Dependency updater for on-chain Soroban contracts: pins third-party contract code, detects upgrades, documents and proposes a re-pin.",
5
+ "license": "MIT",
6
+ "type": "module",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "git+https://github.com/LumenWipe/wasmlock.git"
10
+ },
11
+ "bugs": {
12
+ "url": "https://github.com/LumenWipe/wasmlock/issues"
13
+ },
14
+ "homepage": "https://github.com/LumenWipe/wasmlock#readme",
15
+ "keywords": ["stellar", "soroban", "smart-contracts", "lockfile", "upgrade"],
16
+ "engines": {
17
+ "node": ">=22"
18
+ },
19
+ "bin": {
20
+ "wasmlock": "./dist/cli.js"
21
+ },
22
+ "exports": {
23
+ ".": {
24
+ "types": "./dist/index.d.ts",
25
+ "default": "./dist/index.js"
26
+ }
27
+ },
28
+ "files": ["dist", "schema", "LICENSE", "README.md", "THIRD_PARTY_NOTICES.txt"],
29
+ "publishConfig": {
30
+ "access": "public",
31
+ "provenance": true
32
+ },
33
+ "scripts": {
34
+ "build": "bun scripts/build.ts",
35
+ "typecheck": "tsc --noEmit",
36
+ "lint": "eslint .",
37
+ "test": "bun test",
38
+ "guard": "bun scripts/guard-names.ts",
39
+ "verify": "bun run typecheck && bun run lint && bun run test && bun run guard"
40
+ },
41
+ "devDependencies": {
42
+ "@eslint/js": "9.39.1",
43
+ "@stellar/stellar-sdk": "17.4.0",
44
+ "@types/bun": "1.3.14",
45
+ "@types/node": "22.19.1",
46
+ "eslint": "9.39.1",
47
+ "typescript": "5.9.3",
48
+ "typescript-eslint": "8.48.0"
49
+ }
50
+ }
@@ -0,0 +1,90 @@
1
+ {
2
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
3
+ "title": "wasmlock rules file",
4
+ "description": "The structure of wasmlock.rules.json. wasmlock validates more than a schema can say: the file is at most 65536 bytes, rule names are unique and never a built-in preset name, a key name and a key are not repeated inside a rule, `candidate` names a hash key, `deadline` names a u32 or u64 key, `fires.key` names a key of the rule, `nonzero` applies to numeric and bool keys only, address parts must have a valid checksum, and an object may not repeat a JSON key. The tool is the authority.",
5
+ "type": "object",
6
+ "additionalProperties": false,
7
+ "required": ["version", "rules"],
8
+ "properties": {
9
+ "version": { "const": 1 },
10
+ "rules": {
11
+ "type": "array",
12
+ "maxItems": 50,
13
+ "items": { "$ref": "#/$defs/rule" }
14
+ }
15
+ },
16
+ "$defs": {
17
+ "rule": {
18
+ "type": "object",
19
+ "additionalProperties": false,
20
+ "required": ["name", "keys", "fires"],
21
+ "properties": {
22
+ "name": { "type": "string", "pattern": "^[a-z][a-z0-9-]{0,63}$" },
23
+ "description": { "type": "string", "maxLength": 200 },
24
+ "keys": { "type": "array", "minItems": 1, "maxItems": 8, "items": { "$ref": "#/$defs/keyRead" } },
25
+ "candidate": { "type": "string", "pattern": "^[A-Za-z][A-Za-z0-9_]{0,31}$" },
26
+ "deadline": { "type": "string", "pattern": "^[A-Za-z][A-Za-z0-9_]{0,31}$" },
27
+ "fires": {
28
+ "type": "object",
29
+ "additionalProperties": false,
30
+ "required": ["key", "when"],
31
+ "properties": {
32
+ "key": { "type": "string", "pattern": "^[A-Za-z][A-Za-z0-9_]{0,31}$" },
33
+ "when": { "enum": ["nonzero", "present"] }
34
+ }
35
+ }
36
+ }
37
+ },
38
+ "keyRead": {
39
+ "type": "object",
40
+ "additionalProperties": false,
41
+ "required": ["name", "key", "type"],
42
+ "properties": {
43
+ "name": { "type": "string", "pattern": "^[A-Za-z][A-Za-z0-9_]{0,31}$" },
44
+ "key": { "$ref": "#/$defs/keySpec" },
45
+ "type": { "enum": ["u32", "u64", "i128", "u128", "bool", "address", "hash", "string", "symbol"] }
46
+ }
47
+ },
48
+ "symbol": { "type": "string", "pattern": "^[A-Za-z0-9_]{1,32}$" },
49
+ "keySpec": {
50
+ "oneOf": [
51
+ { "$ref": "#/$defs/symbol" },
52
+ {
53
+ "type": "object",
54
+ "additionalProperties": false,
55
+ "required": ["symbol"],
56
+ "properties": { "symbol": { "$ref": "#/$defs/symbol" } }
57
+ },
58
+ {
59
+ "type": "object",
60
+ "additionalProperties": false,
61
+ "required": ["vec"],
62
+ "properties": { "vec": { "type": "array", "minItems": 1, "maxItems": 8, "items": { "$ref": "#/$defs/keyPart" } } }
63
+ }
64
+ ]
65
+ },
66
+ "keyPart": {
67
+ "oneOf": [
68
+ { "$ref": "#/$defs/symbol" },
69
+ {
70
+ "type": "object",
71
+ "additionalProperties": false,
72
+ "required": ["u32"],
73
+ "properties": { "u32": { "type": "integer", "minimum": 0, "maximum": 4294967295 } }
74
+ },
75
+ {
76
+ "type": "object",
77
+ "additionalProperties": false,
78
+ "required": ["bool"],
79
+ "properties": { "bool": { "type": "boolean" } }
80
+ },
81
+ {
82
+ "type": "object",
83
+ "additionalProperties": false,
84
+ "required": ["address"],
85
+ "properties": { "address": { "type": "string", "pattern": "^[GC][A-Z2-7]{55}$" } }
86
+ }
87
+ ]
88
+ }
89
+ }
90
+ }