@stellar-registry/perch-contracts 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,564 @@
1
+ /** sha256 of the wasm these bindings were generated from. */
2
+ export declare const WASM_SHA256 = "ccea12cd4b2f23d9bce07e3d9d3aaf93c43df79416b22a8c9a122d467b707853";
3
+ import { Buffer } from "buffer";
4
+ import { AssembledTransaction, Client as ContractClient, ClientOptions as ContractClientOptions, MethodOptions, Result } from "@stellar/stellar-sdk/contract";
5
+ import type { u32, i128, Option } from "@stellar/stellar-sdk/contract";
6
+ export * from "@stellar/stellar-sdk";
7
+ export * as contract from "@stellar/stellar-sdk/contract";
8
+ export * as rpc from "@stellar/stellar-sdk/rpc";
9
+ /**
10
+ * The document caps a compiler enforces, as [`PerchDocCompiler::limits`]
11
+ * returns them. Versioned: a later budget (a complexity-weighted one, say)
12
+ * is a new variant, which a consumer that does not know it refuses rather
13
+ * than misreads.
14
+ */
15
+ export type DocLimits = {
16
+ tag: "V1";
17
+ values: readonly [FlatDocLimits];
18
+ };
19
+ /**
20
+ * Where a compiled rule applies. `SelfAdmin` is account-agnostic: the
21
+ * applying account resolves it to its own address.
22
+ */
23
+ export type RuleScope = {
24
+ tag: "SelfAdmin";
25
+ values: void;
26
+ } | {
27
+ tag: "Contract";
28
+ values: readonly [string];
29
+ };
30
+ /**
31
+ * A cumulative spend cap lowered to OZ `spending_limit`'s install params
32
+ * (`SpendingLimitAccountParams`). The tracked token is the rule's scope
33
+ * contract, so it is not carried here.
34
+ */
35
+ export interface CompiledCap {
36
+ /**
37
+ * Rolling-window length in ledgers.
38
+ */
39
+ period_ledgers: u32;
40
+ /**
41
+ * Cumulative amount ceiling over the rolling window.
42
+ */
43
+ spending_limit: i128;
44
+ }
45
+ /**
46
+ * A compiled document: its canonical identity and the rules it becomes.
47
+ */
48
+ export interface CompiledDoc {
49
+ /**
50
+ * The canonical bytes `doc_hash` is the hash of. The account stores
51
+ * them so anyone, including the recovery controller, can read back the
52
+ * full applied document.
53
+ */
54
+ canonical: Buffer;
55
+ /**
56
+ * `sha256(canonical bytes)` — the hash the reviewer approved. Formatting
57
+ * of the submitted JSON is irrelevant: a pretty-printed file and its
58
+ * minified twin compile to the same hash.
59
+ */
60
+ doc_hash: Buffer;
61
+ /**
62
+ * The fingerprint (`perch_recovery_interface::credential::Credential::
63
+ * fingerprint`) of every declared signer's credential, with external
64
+ * keys canonicalized by their verifier. What revocation compares
65
+ * (spec §8).
66
+ */
67
+ fingerprints: Array<Buffer>;
68
+ /**
69
+ * Zero or one entries — a `Vec` because `CompiledRecoveryConfig` is
70
+ * itself a `#[contracttype]` struct (see [`CompiledRule::install`]'s
71
+ * doc comment for why `Option<CompiledRecoveryConfig>` doesn't compile
72
+ * here). Present ⇒ the document enrolls account recovery — the applier
73
+ * is expected to sync this configuration to the adopted
74
+ * recovery-controller instance named in it. See `docs/recovery/` for
75
+ * the full design; wire-compat notes live there too (this is a new
76
+ * field on an existing constructorless, immutable deployable — a
77
+ * compiler build carrying it is a new instance, not an in-place change
78
+ * to any already-deployed one).
79
+ */
80
+ recovery: Array<CompiledRecoveryConfig>;
81
+ rules: Array<CompiledRule>;
82
+ }
83
+ /**
84
+ * One rule, compiled to the exact shapes OZ's `add_context_rule` takes:
85
+ * resolved addresses, OZ `Signer`s, and (for constrained rules) the
86
+ * interpreter program as `InstallParams`.
87
+ */
88
+ export interface CompiledRule {
89
+ /**
90
+ * Zero or one entries (a `Vec` for the same reason as `install` —
91
+ * `CompiledCap` is itself a `#[contracttype]` struct). Present ⇒ also
92
+ * attach OZ `spending_limit` with these params — the cumulative cap the
93
+ * stateless interpreter cannot express. The applier resolves the
94
+ * policy's content-addressed address and keys it into the rule's policy
95
+ * map beside the interpreter; the tracked token is the rule's `Contract`
96
+ * scope (validation pins `token == scope`).
97
+ */
98
+ cap: Array<CompiledCap>;
99
+ /**
100
+ * Zero or one entries — a `Vec` rather than `Option<CompiledCap>`-style
101
+ * `Option` because `InstallParams` is itself a `#[contracttype]` struct,
102
+ * and `#[contracttype]`'s derive macro has no `ScVal`/spec conversion
103
+ * for `Option<T>` where `T` is a custom struct or enum (confirmed
104
+ * directly: it fails to compile with "the trait bound `ScVal:
105
+ * TryFrom<&Option<T>>` is not satisfied" — `Option<u32>` on
106
+ * `valid_until` above works because `u32` is a host-builtin type with
107
+ * its own direct `ScVal` conversion, not because `Option` itself is the
108
+ * problem). Empty ⇒ policy-free rule.
109
+ */
110
+ install: Array<InstallParams>;
111
+ name: string;
112
+ scope: RuleScope;
113
+ signers: Array<Signer>;
114
+ valid_until: Option<u32>;
115
+ }
116
+ /**
117
+ * What `derive_target` returns: the recovery target the controller binds
118
+ * into an attempt's statement (spec §7.1).
119
+ */
120
+ export interface DerivedTarget {
121
+ /**
122
+ * The target's canonical bytes: exactly what the completing `apply_doc`
123
+ * must submit.
124
+ */
125
+ canonical: Buffer;
126
+ /**
127
+ * The target's recovery `config_hash` (the current one, or the current
128
+ * one with the declared ZK rotation).
129
+ */
130
+ config_hash: Buffer;
131
+ doc_hash: Buffer;
132
+ /**
133
+ * Fingerprints of every credential in the target (spec §7.3 rule 7).
134
+ */
135
+ fingerprints: Array<Buffer>;
136
+ /**
137
+ * The credentials occupying the replaced signer slots in the source:
138
+ * the applied document's for lost-key, the baseline's for compromise.
139
+ * External keys are canonicalized by their verifier, so a credential's
140
+ * `fingerprint` is the one revocation compares. The controller records
141
+ * them at T1 and the completion revokes them (spec §8).
142
+ */
143
+ replaced: Array<Credential>;
144
+ }
145
+ /**
146
+ * Flat per-document caps: [`MAX_DOC_SIGNERS`], [`MAX_DOC_RULES`],
147
+ * [`MAX_DOC_CANONICAL_BYTES`], [`MAX_RULE_NAME_BYTES`].
148
+ */
149
+ export interface FlatDocLimits {
150
+ max_canonical_bytes: u32;
151
+ max_rule_name_bytes: u32;
152
+ max_rules: u32;
153
+ max_signers: u32;
154
+ }
155
+ /**
156
+ * Everything `compile_doc` can refuse. (`#[scerr]` assigns sequential codes
157
+ * from 1, in variant order.)
158
+ */
159
+ export declare const DocCompilerError: {
160
+ /**
161
+ * The submitted document bytes are not UTF-8.
162
+ */
163
+ 1: {
164
+ message: string;
165
+ };
166
+ /**
167
+ * The document failed fail-closed parsing (unknown field, bad shape, unsupported version, duplicate key, …).
168
+ */
169
+ 2: {
170
+ message: string;
171
+ };
172
+ /**
173
+ * The document failed semantic validation (dangling signer ref, malformed address or key, ambiguous empty list, …).
174
+ */
175
+ 3: {
176
+ message: string;
177
+ };
178
+ /**
179
+ * The document names no network, or a network that is not this chain.
180
+ */
181
+ 4: {
182
+ message: string;
183
+ };
184
+ /**
185
+ * The document cannot be lowered to rules (unsupported rule shape).
186
+ */
187
+ 5: {
188
+ message: string;
189
+ };
190
+ /**
191
+ * The document exceeds a document cap ([`MAX_DOC_SIGNERS`], [`MAX_DOC_RULES`], [`MAX_DOC_CANONICAL_BYTES`], [`MAX_RULE_NAME_BYTES`]).
192
+ */
193
+ 6: {
194
+ message: string;
195
+ };
196
+ /**
197
+ * A signer's external `key` is not its verifier-canonical form: either the verifier could not canonicalize it at all, or the declared bytes differ from the canonical form the verifier returns (e.g. a WebAuthn key carrying a credential-id suffix the verifier drops, or a non-canonical point encoding). The compiler refuses it rather than silently canonicalizing, so the bytes the document hash — and a recovery attempt's `replacements_hash` — bind are exactly the bytes the installed credential uses, and two signers cannot hide one physical key under two spellings.
198
+ */
199
+ 7: {
200
+ message: string;
201
+ };
202
+ /**
203
+ * `derive_target`: the current document enrolls no recovery.
204
+ */
205
+ 8: {
206
+ message: string;
207
+ };
208
+ /**
209
+ * `derive_target`: the replacement set breaks spec §7.3 rules 1-3 (not canonical, empty for lost-key, a signer id that is not replaceable or not declared in the source, or a change of credential kind or verifier), or the action is not a recovery attempt.
210
+ */
211
+ 9: {
212
+ message: string;
213
+ };
214
+ /**
215
+ * `derive_target`: the ZK enrollment is missing for a ZK mode, present for a guardian-only mode, or reuses the enrolled id.
216
+ */
217
+ 10: {
218
+ message: string;
219
+ };
220
+ /**
221
+ * `derive_target`: the target has no policy-free self-admin rule with a signer (the anti-brick check).
222
+ */
223
+ 11: {
224
+ message: string;
225
+ };
226
+ };
227
+ /**
228
+ * The canonical form and fragment hashes a compiler produces, as
229
+ * [`PerchDocCompiler::capabilities`] returns them.
230
+ */
231
+ export interface CompilerCapabilities {
232
+ /**
233
+ * The CANON version `doc_hash` is `sha256` of (`CANONICAL.md`).
234
+ */
235
+ canon_version: u32;
236
+ /**
237
+ * The domain tag of a recovery member's `config_hash` (spec §3.2).
238
+ */
239
+ config_hash_tag: string;
240
+ /**
241
+ * The domain tag of a rule's `rule_hash` (spec §3.2).
242
+ */
243
+ rule_hash_tag: string;
244
+ }
245
+ /**
246
+ * One op of a postfix-encoded constraint program.
247
+ */
248
+ export type Op = {
249
+ tag: "All";
250
+ values: readonly [u32];
251
+ } | {
252
+ tag: "Any";
253
+ values: readonly [u32];
254
+ } | {
255
+ tag: "Not";
256
+ values: void;
257
+ } | {
258
+ tag: "MinSigners";
259
+ values: readonly [u32];
260
+ } | {
261
+ tag: "FnIn";
262
+ values: readonly [Array<string>];
263
+ } | {
264
+ tag: "ArgAddrEq";
265
+ values: readonly [u32, string];
266
+ } | {
267
+ tag: "ArgAddrIsSelf";
268
+ values: readonly [u32];
269
+ } | {
270
+ tag: "ArgSymEq";
271
+ values: readonly [u32, string];
272
+ } | {
273
+ tag: "ArgStrIn";
274
+ values: readonly [u32, Array<string>];
275
+ } | {
276
+ tag: "ArgStrPrefix";
277
+ values: readonly [u32, string];
278
+ } | {
279
+ tag: "ArgBytesEq";
280
+ values: readonly [u32, Buffer];
281
+ } | {
282
+ tag: "ArgI128Eq";
283
+ values: readonly [u32, i128];
284
+ } | {
285
+ tag: "ArgU32Eq";
286
+ values: readonly [u32, u32];
287
+ } | {
288
+ tag: "ArgCount";
289
+ values: readonly [u32];
290
+ } | {
291
+ tag: "LedgerBefore";
292
+ values: readonly [u32];
293
+ } | {
294
+ tag: "LedgerAtOrAfter";
295
+ values: readonly [u32];
296
+ };
297
+ /**
298
+ * A postfix-encoded constraint program. The last op produces the root
299
+ * verdict.
300
+ */
301
+ export interface RpnProgram {
302
+ ops: Array<Op>;
303
+ version: u32;
304
+ }
305
+ /**
306
+ * What the compiler stores in the interpreter for one `(account, rule)`: the
307
+ * program plus the `doc_hash` of the source PolicyDoc. Sharing this
308
+ * `#[contracttype]` between the compiler and the interpreter is what keeps
309
+ * install params from ever being a hand-built `ScVal` — both sides encode and
310
+ * decode through exactly these types. `doc_hash` binds the on-chain program to
311
+ * the reviewed document (provenance for lift/diff).
312
+ */
313
+ export interface InstallParams {
314
+ doc_hash: Buffer;
315
+ program: RpnProgram;
316
+ }
317
+ /**
318
+ * A signer credential, shaped like OZ `stellar_accounts::smart_account::Signer`.
319
+ */
320
+ export type Credential = {
321
+ tag: "Delegated";
322
+ values: readonly [string];
323
+ } | {
324
+ tag: "External";
325
+ values: readonly [string, Buffer];
326
+ };
327
+ /**
328
+ * One designated signer slot and the credential that replaces whatever
329
+ * that slot holds in the source document.
330
+ */
331
+ export interface Replacement {
332
+ /**
333
+ * The credential the target document gives that signer id.
334
+ */
335
+ credential: Credential;
336
+ /**
337
+ * A document signer id listed in the enrolled `recovery.replaceable`.
338
+ */
339
+ signer_id: string;
340
+ }
341
+ /**
342
+ * A ZK enrollment a recovery completion installs.
343
+ *
344
+ * The commitment is bound here, not only the id: completion runs under the
345
+ * zero-signer recovery rule, so nothing signs its arguments, and a
346
+ * commitment supplied only at completion could be swapped by whoever
347
+ * submits the completing transaction first — handing them the account's
348
+ * next ZK factor.
349
+ */
350
+ export interface ZkEnrollment {
351
+ /**
352
+ * The new leaf's inner commitment, `Poseidon2(DOM_LEAF, secret)`.
353
+ * Derivation writes `id` and `commitment` into the target document's
354
+ * recovery section, so the target hash binds them, and the completing
355
+ * `apply_doc` inserts the leaf from the compiled target, never from a
356
+ * call argument.
357
+ */
358
+ commitment: Buffer;
359
+ /**
360
+ * The new enrollment id. Must never have been enrolled for this
361
+ * account before.
362
+ */
363
+ id: Buffer;
364
+ }
365
+ /**
366
+ * Everything a `LostKey`/`Compromise` attempt changes about the source
367
+ * document. See `docs/recovery/spec.md` §7.
368
+ */
369
+ export interface ReplacementSet {
370
+ /**
371
+ * Signer replacements in strictly ascending `signer_id` byte order
372
+ * (sorted, no duplicates) — the one canonical order.
373
+ */
374
+ signers: Array<Replacement>;
375
+ /**
376
+ * The fresh ZK enrollment the completion installs, required exactly
377
+ * when the enrolled mode has a ZK factor (a ZK-evidenced completion
378
+ * consumes the enrolled credential, so it must install a fresh one).
379
+ * Empty or one entry — a `Vec` because `#[contracttype]` cannot derive
380
+ * `Option<CustomStruct>`.
381
+ */
382
+ zk_enrollment: Array<ZkEnrollment>;
383
+ }
384
+ /**
385
+ * Who may change the recovery configuration, and whether an authorized
386
+ * attempt freezes ordinary activity (spec §2, §9).
387
+ */
388
+ export type RecoveryProfile = {
389
+ tag: "Loss";
390
+ values: void;
391
+ } | {
392
+ tag: "Protected";
393
+ values: void;
394
+ };
395
+ /**
396
+ * The ZK factor (spec §3.1, §3.4).
397
+ */
398
+ export interface CompiledZkFactor {
399
+ /**
400
+ * The constructorless ZK adapter the controller calls.
401
+ */
402
+ adapter: string;
403
+ /**
404
+ * `sha256` of the adapter's verification key; must equal the adapter's
405
+ * `circuit_id()`.
406
+ */
407
+ circuit_id: Buffer;
408
+ /**
409
+ * The current credential's inner commitment, `Poseidon2(DOM_LEAF,
410
+ * secret)`, from which the account inserts the leaf.
411
+ */
412
+ commitment: Buffer;
413
+ /**
414
+ * The current credential's id, bound into its leaf and nullifier.
415
+ */
416
+ enrollment_id: Buffer;
417
+ /**
418
+ * The membership pool roots are accepted from.
419
+ */
420
+ pool: string;
421
+ }
422
+ /**
423
+ * The guardian factor.
424
+ */
425
+ export interface CompiledGuardianSet {
426
+ /**
427
+ * Guardian addresses (`G...` or `C...`), never the account itself.
428
+ */
429
+ guardians: Array<string>;
430
+ /**
431
+ * `1 <= quorum <= guardians.len()`.
432
+ */
433
+ quorum: u32;
434
+ }
435
+ /**
436
+ * Which factors a statement needs.
437
+ */
438
+ export type CompiledRecoveryMode = {
439
+ tag: "GuardianOnly";
440
+ values: readonly [CompiledGuardianSet];
441
+ } | {
442
+ tag: "ZkOnly";
443
+ values: readonly [CompiledZkFactor];
444
+ } | {
445
+ tag: "Combined";
446
+ values: readonly [CompiledGuardianSet, CompiledZkFactor];
447
+ };
448
+ /**
449
+ * A compiled `recovery` member.
450
+ */
451
+ export interface CompiledRecoveryConfig {
452
+ /**
453
+ * The enrolled baseline's canonical document hash, if compromise
454
+ * recovery is enrolled.
455
+ */
456
+ baseline: Option<Buffer>;
457
+ /**
458
+ * [`config_hash`] of the canonical JSON of the recovery member, computed
459
+ * by the doc compiler (spec §3.2). Configuration
460
+ * identity: two compiled configurations with the same `config_hash` are
461
+ * the same configuration.
462
+ */
463
+ config_hash: Buffer;
464
+ /**
465
+ * The adopted controller instance.
466
+ */
467
+ controller: string;
468
+ delay_ledgers: u32;
469
+ expiry_ledgers: u32;
470
+ max_cancels: u32;
471
+ mode: CompiledRecoveryMode;
472
+ profile: RecoveryProfile;
473
+ /**
474
+ * Signer ids (not credential fingerprints) a recovery may replace, so
475
+ * rotating a key does not change the configuration (#92).
476
+ */
477
+ replaceable: Array<string>;
478
+ }
479
+ /**
480
+ * The action domain a statement authorizes. Evidence for one action never
481
+ * satisfies another: the action code is the encoding's 26th byte and selects
482
+ * the subject layout, so two statements that differ only in action have
483
+ * different digests (and different encoded lengths for most pairs).
484
+ *
485
+ * The numeric codes are part of the wire format.
486
+ */
487
+ export declare enum RecoveryAction {
488
+ LostKey = 1,
489
+ Compromise = 2,
490
+ Cancel = 3,
491
+ Reconfigure = 4,
492
+ Upgrade = 5
493
+ }
494
+ /**
495
+ * Represents different types of signers in the smart account system.
496
+ */
497
+ export type Signer = {
498
+ tag: "Delegated";
499
+ values: readonly [string];
500
+ } | {
501
+ tag: "External";
502
+ values: readonly [string, Buffer];
503
+ };
504
+ export interface Client {
505
+ /**
506
+ * Construct and simulate a limits transaction. Returns an `AssembledTransaction` object which will have a `result` field containing the result of the simulation. If this transaction changes contract state, you will need to call `signAndSend()` on the returned object.
507
+ * The document caps every `compile_doc` and `derive_target` enforces.
508
+ */
509
+ limits: (options?: MethodOptions) => Promise<AssembledTransaction<DocLimits>>;
510
+ /**
511
+ * Construct and simulate a compile_doc transaction. Returns an `AssembledTransaction` object which will have a `result` field containing the result of the simulation. If this transaction changes contract state, you will need to call `signAndSend()` on the returned object.
512
+ * JSON bytes in → compiled rules + canonical `doc_hash` out. Pure:
513
+ * no auth, no storage. The document must name THIS network (its
514
+ * `network` string must hash to the chain's network id), so a testnet
515
+ * document can never compile on mainnet or vice versa.
516
+ */
517
+ compile_doc: ({ doc_json }: {
518
+ doc_json: Buffer;
519
+ }, options?: MethodOptions) => Promise<AssembledTransaction<Result<CompiledDoc>>>;
520
+ /**
521
+ * Construct and simulate a capabilities transaction. Returns an `AssembledTransaction` object which will have a `result` field containing the result of the simulation. If this transaction changes contract state, you will need to call `signAndSend()` on the returned object.
522
+ * The CANON version and the fragment hash domain tags this compiler
523
+ * produces.
524
+ */
525
+ capabilities: (options?: MethodOptions) => Promise<AssembledTransaction<CompilerCapabilities>>;
526
+ /**
527
+ * Construct and simulate a derive_target transaction. Returns an `AssembledTransaction` object which will have a `result` field containing the result of the simulation. If this transaction changes contract state, you will need to call `signAndSend()` on the returned object.
528
+ * Derive a recovery target (`docs/recovery/spec.md` §7): `source_json`
529
+ * is the account's applied document (lost-key) or the published
530
+ * baseline (compromise); `current_json` is the applied document, whose
531
+ * recovery member the target keeps. The target is the source with
532
+ * exactly the declared replacements and ZK rotation, then validated,
533
+ * network-bound, capped, compiled, and anti-brick-checked like any
534
+ * applied document. Pure: no auth, no storage. The controller calls it
535
+ * when an attempt begins, and completers simulate it to obtain the
536
+ * canonical bytes.
537
+ */
538
+ derive_target: ({ source_json, current_json, action, replacements }: {
539
+ source_json: Buffer;
540
+ current_json: Buffer;
541
+ action: RecoveryAction;
542
+ replacements: ReplacementSet;
543
+ }, options?: MethodOptions) => Promise<AssembledTransaction<Result<DerivedTarget>>>;
544
+ }
545
+ export declare class Client extends ContractClient {
546
+ readonly options: ContractClientOptions;
547
+ static deploy<T = Client>(
548
+ /** Options for initializing a Client as well as for calling a method, with extras specific to deploying. */
549
+ options: MethodOptions & Omit<ContractClientOptions, "contractId"> & {
550
+ /** The hash of the Wasm blob, which must already be installed on-chain. */
551
+ wasmHash: Buffer | string;
552
+ /** Salt used to generate the contract's ID. Passed through to {@link Operation.createCustomContract}. Default: random. */
553
+ salt?: Buffer | Uint8Array;
554
+ /** The format used to decode `wasmHash`, if it's provided as a string. */
555
+ format?: "hex" | "base64";
556
+ }): Promise<AssembledTransaction<T>>;
557
+ constructor(options: ContractClientOptions);
558
+ readonly fromJSON: {
559
+ limits: (json: string) => AssembledTransaction<DocLimits>;
560
+ compile_doc: (json: string) => AssembledTransaction<Result<CompiledDoc, import("@stellar/stellar-sdk/contract").ErrorMessage>>;
561
+ capabilities: (json: string) => AssembledTransaction<CompilerCapabilities>;
562
+ derive_target: (json: string) => AssembledTransaction<Result<DerivedTarget, import("@stellar/stellar-sdk/contract").ErrorMessage>>;
563
+ };
564
+ }