@stellar-registry/perch-contracts 0.1.1 → 0.2.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.
@@ -1,5 +1,7 @@
1
1
  /** sha256 of the wasm these bindings were generated from. */
2
- export declare const WASM_SHA256 = "960b2ce788303ac7d7b41dd0a338268b72bb225b69e54fdcfb86788566a0fcb3";
2
+ export declare const WASM_SHA256 = "e89d977ac2bebaf935720a7a3408f6cd57b5940a02b0476e7b8e071e224b0fe3";
3
+ /** These bindings describe a build no deployment runs yet. */
4
+ export declare const DEPLOYED = false;
3
5
  import { Buffer } from "buffer";
4
6
  import { AssembledTransaction, Client as ContractClient, ClientOptions as ContractClientOptions, MethodOptions, Result } from "@stellar/stellar-sdk/contract";
5
7
  import type { u32, i128, Option } from "@stellar/stellar-sdk/contract";
@@ -27,21 +29,6 @@ export type RuleScope = {
27
29
  tag: "Contract";
28
30
  values: readonly [string];
29
31
  };
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
32
  /**
46
33
  * A compiled document: its canonical identity and the rules it becomes.
47
34
  */
@@ -66,51 +53,72 @@ export interface CompiledDoc {
66
53
  */
67
54
  fingerprints: Array<Buffer>;
68
55
  /**
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).
56
+ * The document as rule-core's lowering reads it (`rule_eval::Doc`, in
57
+ * host types): one entry. A `Vec` for the same reason as `recovery`.
58
+ * The applying account lowers it with `rule_eval::lower` and stores the
59
+ * result as its installed rules; `model.rules[i]` is `rules[i]`'s
60
+ * document rule.
61
+ */
62
+ model: Array<CompiledModel>;
63
+ /**
64
+ * Whether the document is in normal form as far as its text shows
65
+ * (`perch_ir::normal_form`): then the rules an account stores for it,
66
+ * with its signer ids and [`Self::verifier_names`], give back its
67
+ * canonical text. An account refuses a scoped document that is not.
68
+ */
69
+ normal_form: boolean;
70
+ /**
71
+ * The compiled `recovery` member: zero or one entries (a `Vec` because
72
+ * `#[contracttype]` has no conversion for an `Option` of a custom struct;
73
+ * `Option<u32>` on [`CompiledRule::valid_until`] works because `u32` is
74
+ * a host type). Present ⇒ the document enrolls account recovery, and the
75
+ * applier syncs this configuration to the controller instance it names
76
+ * (`docs/recovery/`).
79
77
  */
80
78
  recovery: Array<CompiledRecoveryConfig>;
79
+ /**
80
+ * One compiled rule per document rule, in the submitted order.
81
+ */
81
82
  rules: Array<CompiledRule>;
83
+ /**
84
+ * Every verifier the document names by contract id alone, once each, in
85
+ * declaration order: what a wallet warns about ("it can approve anything
86
+ * this rule allows"). Always empty for an admin document, which may name
87
+ * none.
88
+ */
89
+ unverified: Array<string>;
90
+ /**
91
+ * One entry per declared signer, in declaration order: the
92
+ * `verifier-name` its verifier was resolved from, or empty for a
93
+ * delegated signer and a verifier named by contract id alone.
94
+ */
95
+ verifier_names: Array<string>;
82
96
  }
83
97
  /**
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`.
98
+ * One rule, compiled to the shapes OZ's `add_context_rule` takes: its
99
+ * name, resolved scope, its principals' OZ `Signer`s in the order the
100
+ * document names them, and its last ledger. OZ's context rule is the
101
+ * registry of the rule's id and signers; what the rule allows is its
102
+ * document rule in [`CompiledDoc::model`], at the same index, as rule-eval
103
+ * lowers it.
87
104
  */
88
105
  export interface CompiledRule {
106
+ auth_root: Option<Array<StoredAuthRoot>>;
89
107
  /**
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>;
108
+ * The rule's name in the document. The account matches installed rules
109
+ * by name and scope.
110
+ */
111
111
  name: string;
112
112
  scope: RuleScope;
113
+ /**
114
+ * The rule's signers, with external keys as declared (already
115
+ * verifier-canonical).
116
+ */
113
117
  signers: Array<Signer>;
118
+ /**
119
+ * The last ledger the rule authorizes, if bounded: OZ's inclusive
120
+ * `valid_until`, one below the document's `not-after-ledger`.
121
+ */
114
122
  valid_until: Option<u32>;
115
123
  }
116
124
  /**
@@ -128,6 +136,9 @@ export interface DerivedTarget {
128
136
  * one with the declared ZK rotation).
129
137
  */
130
138
  config_hash: Buffer;
139
+ /**
140
+ * `sha256` of `canonical`: the target's `doc_hash`.
141
+ */
131
142
  doc_hash: Buffer;
132
143
  /**
133
144
  * Fingerprints of every credential in the target (spec §7.3 rule 7).
@@ -144,7 +155,9 @@ export interface DerivedTarget {
144
155
  }
145
156
  /**
146
157
  * Flat per-document caps: [`MAX_DOC_SIGNERS`], [`MAX_DOC_RULES`],
147
- * [`MAX_DOC_CANONICAL_BYTES`], [`MAX_RULE_NAME_BYTES`].
158
+ * [`MAX_DOC_CANONICAL_BYTES`], [`MAX_RULE_NAME_BYTES`] for an account
159
+ * document, and the `MAX_GRANT_*` ones with the same name cap for a grant
160
+ * document.
148
161
  */
149
162
  export interface FlatDocLimits {
150
163
  max_canonical_bytes: u32;
@@ -170,7 +183,7 @@ export declare const DocCompilerError: {
170
183
  message: string;
171
184
  };
172
185
  /**
173
- * The document failed semantic validation (dangling signer ref, malformed address or key, ambiguous empty list, …).
186
+ * The document failed semantic validation (dangling signer ref, malformed address or key, ambiguous empty list, …) or names its verifiers as the compiler does not take.
174
187
  */
175
188
  3: {
176
189
  message: string;
@@ -182,19 +195,19 @@ export declare const DocCompilerError: {
182
195
  message: string;
183
196
  };
184
197
  /**
185
- * The document cannot be lowered to rules (unsupported rule shape).
198
+ * The document cannot be lowered to rules: a rule with self-authenticating principals, or too many constraints.
186
199
  */
187
200
  5: {
188
201
  message: string;
189
202
  };
190
203
  /**
191
- * The document exceeds a document cap ([`MAX_DOC_SIGNERS`], [`MAX_DOC_RULES`], [`MAX_DOC_CANONICAL_BYTES`], [`MAX_RULE_NAME_BYTES`]).
204
+ * The document exceeds a cap on signers, rules, bytes, or name length.
192
205
  */
193
206
  6: {
194
207
  message: string;
195
208
  };
196
209
  /**
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.
210
+ * A signer's external `key` is not its verifier-canonical form.
198
211
  */
199
212
  7: {
200
213
  message: string;
@@ -206,19 +219,19 @@ export declare const DocCompilerError: {
206
219
  message: string;
207
220
  };
208
221
  /**
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.
222
+ * `derive_target`: the replacement set breaks spec §7.3 rules 1-3, or the action is not a recovery attempt.
210
223
  */
211
224
  9: {
212
225
  message: string;
213
226
  };
214
227
  /**
215
- * `derive_target`: the ZK enrollment is missing for a ZK mode, present for a guardian-only mode, or reuses the enrolled id.
228
+ * `derive_target`: the ZK enrollment is missing, unexpected, or reuses the enrolled id.
216
229
  */
217
230
  10: {
218
231
  message: string;
219
232
  };
220
233
  /**
221
- * `derive_target`: the target has no policy-free self-admin rule with a signer (the anti-brick check).
234
+ * `derive_target`: the target has no constraint-free self-admin rule with a signer (the anti-brick check).
222
235
  */
223
236
  11: {
224
237
  message: string;
@@ -243,77 +256,15 @@ export interface CompilerCapabilities {
243
256
  rule_hash_tag: string;
244
257
  }
245
258
  /**
246
- * One op of a postfix-encoded constraint program.
259
+ * Represents different types of signers in the smart account system.
247
260
  */
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];
261
+ export type Signer = {
262
+ tag: "Delegated";
263
+ values: readonly [string];
293
264
  } | {
294
- tag: "LedgerAtOrAfter";
295
- values: readonly [u32];
265
+ tag: "External";
266
+ values: readonly [string, Buffer];
296
267
  };
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
268
  /**
318
269
  * A signer credential, shaped like OZ `stellar_accounts::smart_account::Signer`.
319
270
  */
@@ -465,10 +416,27 @@ export interface CompiledRecoveryConfig {
465
416
  * The adopted controller instance.
466
417
  */
467
418
  controller: string;
419
+ /**
420
+ * Ledgers from an attempt's authorization until it can complete.
421
+ */
468
422
  delay_ledgers: u32;
423
+ /**
424
+ * The evidence window of a collecting attempt and the completion
425
+ * window of an authorized one, in ledgers.
426
+ */
469
427
  expiry_ledgers: u32;
428
+ /**
429
+ * Lifetime cap on evidence-based cancellations of authorized attempts.
430
+ */
470
431
  max_cancels: u32;
432
+ /**
433
+ * The factors evidence must satisfy.
434
+ */
471
435
  mode: CompiledRecoveryMode;
436
+ /**
437
+ * Who may change the configuration, and whether an authorized attempt
438
+ * freezes the account.
439
+ */
472
440
  profile: RecoveryProfile;
473
441
  /**
474
442
  * Signer ids (not credential fingerprints) a recovery may replace, so
@@ -492,19 +460,126 @@ export declare enum RecoveryAction {
492
460
  Upgrade = 5
493
461
  }
494
462
  /**
495
- * Represents different types of signers in the smart account system.
463
+ * `rule_eval::ZkFactor`.
496
464
  */
497
- export type Signer = {
498
- tag: "Delegated";
465
+ export interface ModelZk {
466
+ adapter: string;
467
+ pool: string;
468
+ }
469
+ /**
470
+ * `rule_eval::ArgConstraint`.
471
+ */
472
+ export interface ModelArg {
473
+ index: u32;
474
+ pred: ModelPred;
475
+ }
476
+ /**
477
+ * `rule_eval::DocCap`.
478
+ */
479
+ export interface ModelCap {
480
+ limit: i128;
481
+ period_ledgers: u32;
482
+ }
483
+ /**
484
+ * `rule_eval::Pred`.
485
+ */
486
+ export type ModelPred = {
487
+ tag: "IsSelf";
488
+ values: void;
489
+ } | {
490
+ tag: "AddressEq";
499
491
  values: readonly [string];
500
492
  } | {
501
- tag: "External";
502
- values: readonly [string, Buffer];
493
+ tag: "StringIn";
494
+ values: readonly [Array<string>];
495
+ } | {
496
+ tag: "StringPrefix";
497
+ values: readonly [string];
498
+ } | {
499
+ tag: "U32Eq";
500
+ values: readonly [u32];
503
501
  };
502
+ /**
503
+ * `rule_eval::DocRule`.
504
+ */
505
+ export interface ModelRule {
506
+ args: Option<Array<ModelArg>>;
507
+ /**
508
+ * Exact authorization-entry root (contract, function), or unrestricted.
509
+ */
510
+ auth_root: Option<Array<StoredAuthRoot>>;
511
+ /**
512
+ * Zero or one entries: `#[contracttype]` has no `Option` of a
513
+ * `#[contracttype]` struct.
514
+ */
515
+ cap: Array<ModelCap>;
516
+ functions: Option<Array<string>>;
517
+ not_after_ledger: Option<u32>;
518
+ principals: ModelPrincipals;
519
+ scope: ModelScope;
520
+ }
521
+ /**
522
+ * `rule_eval::Scope`.
523
+ */
524
+ export type ModelScope = {
525
+ tag: "Contract";
526
+ values: readonly [string];
527
+ } | {
528
+ tag: "SelfAdmin";
529
+ values: void;
530
+ };
531
+ /**
532
+ * `rule_eval::SignerDecl`.
533
+ */
534
+ export interface ModelSigner {
535
+ id: string;
536
+ signer: Signer;
537
+ }
538
+ /**
539
+ * `rule_eval::Doc`.
540
+ */
541
+ export interface CompiledModel {
542
+ /**
543
+ * Zero or one entries.
544
+ */
545
+ recovery: Array<ModelRecovery>;
546
+ rules: Array<ModelRule>;
547
+ signers: Array<ModelSigner>;
548
+ }
549
+ /**
550
+ * `rule_eval::Recovery`.
551
+ */
552
+ export interface ModelRecovery {
553
+ controller: string;
554
+ /**
555
+ * Zero or one entries.
556
+ */
557
+ zk: Array<ModelZk>;
558
+ }
559
+ /**
560
+ * `rule_eval::Principals`: signer ids.
561
+ */
562
+ export type ModelPrincipals = {
563
+ tag: "All";
564
+ values: readonly [Array<string>];
565
+ } | {
566
+ tag: "Threshold";
567
+ values: readonly [Array<string>, u32];
568
+ };
569
+ /**
570
+ * Exact authorization-entry root in host form.
571
+ */
572
+ export interface StoredAuthRoot {
573
+ contract: string;
574
+ function: string;
575
+ }
504
576
  export interface Client {
505
577
  /**
506
578
  * 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.
579
+ * The caps every `compile_doc` and `derive_target` enforces on an
580
+ * account document: one with a self-admin rule or a recovery member,
581
+ * which is every document `apply_doc` applies and every recovery
582
+ * target.
508
583
  */
509
584
  limits: (options?: MethodOptions) => Promise<AssembledTransaction<DocLimits>>;
510
585
  /**
@@ -512,7 +587,11 @@ export interface Client {
512
587
  * JSON bytes in → compiled rules + canonical `doc_hash` out. Pure:
513
588
  * no auth, no storage. The document must name THIS network (its
514
589
  * `network` string must hash to the chain's network id), so a testnet
515
- * document can never compile on mainnet or vice versa.
590
+ * document can never compile on mainnet or vice versa. It must also fit
591
+ * its caps ([`Self::limits`] for an account document,
592
+ * [`Self::grant_limits`] for a grant document), and every external signer key
593
+ * must already be its verifier-canonical form: the compiler calls each
594
+ * named verifier's `batch_canonicalize_key` to check.
516
595
  */
517
596
  compile_doc: ({ doc_json }: {
518
597
  doc_json: Buffer;
@@ -523,6 +602,13 @@ export interface Client {
523
602
  * produces.
524
603
  */
525
604
  capabilities: (options?: MethodOptions) => Promise<AssembledTransaction<CompilerCapabilities>>;
605
+ /**
606
+ * Construct and simulate a grant_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.
607
+ * The caps `compile_doc` enforces on a grant document: one with no
608
+ * self-admin rule and no recovery member, which is every document
609
+ * `apply_grant` applies.
610
+ */
611
+ grant_limits: (options?: MethodOptions) => Promise<AssembledTransaction<DocLimits>>;
526
612
  /**
527
613
  * 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
614
  * Derive a recovery target (`docs/recovery/spec.md` §7): `source_json`
@@ -541,6 +627,12 @@ export interface Client {
541
627
  action: RecoveryAction;
542
628
  replacements: ReplacementSet;
543
629
  }, options?: MethodOptions) => Promise<AssembledTransaction<Result<DerivedTarget>>>;
630
+ /**
631
+ * Construct and simulate a verifier_registry 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.
632
+ * The `perch/verifiers` registry a `verifier-name` resolves in, on this
633
+ * network.
634
+ */
635
+ verifier_registry: (options?: MethodOptions) => Promise<AssembledTransaction<string>>;
544
636
  }
545
637
  export declare class Client extends ContractClient {
546
638
  readonly options: ContractClientOptions;
@@ -559,6 +651,8 @@ export declare class Client extends ContractClient {
559
651
  limits: (json: string) => AssembledTransaction<DocLimits>;
560
652
  compile_doc: (json: string) => AssembledTransaction<Result<CompiledDoc, import("@stellar/stellar-sdk/contract").ErrorMessage>>;
561
653
  capabilities: (json: string) => AssembledTransaction<CompilerCapabilities>;
654
+ grant_limits: (json: string) => AssembledTransaction<DocLimits>;
562
655
  derive_target: (json: string) => AssembledTransaction<Result<DerivedTarget, import("@stellar/stellar-sdk/contract").ErrorMessage>>;
656
+ verifier_registry: (json: string) => AssembledTransaction<string>;
563
657
  };
564
658
  }