@stellar-registry/perch-contracts 0.1.2 → 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.
@@ -12,6 +12,18 @@ export interface DeployedContract {
12
12
  /** sha256 of every contract this one was built against. */
13
13
  pins: Record<string, string>;
14
14
  }
15
+ /** A verifier in `perch/verifiers`. `contracts.<name>.address` is the
16
+ * registry's copy of the same bytes, which no account admits as an admin
17
+ * verifier. */
18
+ export interface DeployedVerifier {
19
+ version: string;
20
+ sha256: string;
21
+ bytes: number;
22
+ /** Its `verifier-name`: `<name>@<version>`. */
23
+ name: string;
24
+ /** Its content address in `perch/verifiers`: what a document names. */
25
+ address: string;
26
+ }
15
27
  export interface Deployment {
16
28
  schema: number;
17
29
  network: string;
@@ -33,6 +45,18 @@ export interface Deployment {
33
45
  manager: string;
34
46
  root: string;
35
47
  };
48
+ /** `perch/verifiers`, where a document's `verifier-name` resolves and the
49
+ * factory pins its WebAuthn verifier, with each stack verifier it serves.
50
+ * Absent from a deployment that predates it, whose factory pins the
51
+ * registry's copy. */
52
+ verifiers?: {
53
+ id: string;
54
+ wasm_hash: string;
55
+ admin: string;
56
+ manager: string;
57
+ root: string;
58
+ contracts: Record<string, DeployedVerifier>;
59
+ };
36
60
  zk: {
37
61
  circuit_id: string;
38
62
  tree_depth: number;
@@ -40,5 +64,6 @@ export interface Deployment {
40
64
  };
41
65
  contracts: Record<string, DeployedContract>;
42
66
  }
43
- /** The address of `contract` in `deployment`. */
67
+ /** The address of `contract` in `deployment`, under its registry. A verifier
68
+ * a document names is `deployment.verifiers.contracts[name].address`. */
44
69
  export declare function addressOf(deployment: Deployment, contract: string): string;
@@ -1,7 +1,8 @@
1
1
  // The shape of a deployment manifest (deployments/<network>.json, written by
2
2
  // scripts/deploy-stack.sh and checked against the chain by
3
3
  // scripts/verify-deployment.sh).
4
- /** The address of `contract` in `deployment`. */
4
+ /** The address of `contract` in `deployment`, under its registry. A verifier
5
+ * a document names is `deployment.verifiers.contracts[name].address`. */
5
6
  export function addressOf(deployment, contract) {
6
7
  const address = deployment.contracts[contract]?.address;
7
8
  if (!address)
@@ -1,5 +1,7 @@
1
1
  /** sha256 of the wasm these bindings were generated from. */
2
- export declare const WASM_SHA256 = "2730a7d39d619579bb7873818900fa5f9150d69d49fa1ee3b4a38f61ba768a16";
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,39 +53,57 @@ export interface CompiledDoc {
66
53
  */
67
54
  fingerprints: Array<Buffer>;
68
55
  /**
69
- * The compiled `recovery` member: zero or one entries (a `Vec` for the
70
- * same reason as [`CompiledRule::install`]). Present ⇒ the document
71
- * enrolls account recovery, and the applier syncs this configuration to
72
- * the controller instance it names (`docs/recovery/`).
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/`).
73
77
  */
74
78
  recovery: Array<CompiledRecoveryConfig>;
75
79
  /**
76
80
  * One compiled rule per document rule, in the submitted order.
77
81
  */
78
82
  rules: Array<CompiledRule>;
79
- }
80
- /**
81
- * One rule, compiled to the exact shapes OZ's `add_context_rule` takes:
82
- * resolved addresses, OZ `Signer`s, and (for constrained rules) the
83
- * interpreter program as `InstallParams`.
84
- */
85
- export interface CompiledRule {
86
83
  /**
87
- * Zero or one entries (a `Vec` for the same reason as `install`).
88
- * Present ⇒ also attach OZ `spending_limit` with these params — the
89
- * cumulative cap the stateless interpreter cannot express. The applier
90
- * resolves the policy's content-addressed address and keys it into the
91
- * rule's policy map beside the interpreter; the tracked token is the
92
- * rule's `Contract` scope (validation pins `token == scope`).
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.
93
88
  */
94
- cap: Array<CompiledCap>;
89
+ unverified: Array<string>;
95
90
  /**
96
- * The interpreter program to attach: zero or one entries. A `Vec`
97
- * because `#[contracttype]` has no conversion for `Option` of a custom
98
- * struct (`Option<u32>` on `valid_until` works because `u32` is a host
99
- * type). Empty ⇒ a policy-free rule.
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.
100
94
  */
101
- install: Array<InstallParams>;
95
+ verifier_names: Array<string>;
96
+ }
97
+ /**
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.
104
+ */
105
+ export interface CompiledRule {
106
+ auth_root: Option<Array<StoredAuthRoot>>;
102
107
  /**
103
108
  * The rule's name in the document. The account matches installed rules
104
109
  * by name and scope.
@@ -150,7 +155,9 @@ export interface DerivedTarget {
150
155
  }
151
156
  /**
152
157
  * Flat per-document caps: [`MAX_DOC_SIGNERS`], [`MAX_DOC_RULES`],
153
- * [`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.
154
161
  */
155
162
  export interface FlatDocLimits {
156
163
  max_canonical_bytes: u32;
@@ -176,7 +183,7 @@ export declare const DocCompilerError: {
176
183
  message: string;
177
184
  };
178
185
  /**
179
- * 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.
180
187
  */
181
188
  3: {
182
189
  message: string;
@@ -188,19 +195,19 @@ export declare const DocCompilerError: {
188
195
  message: string;
189
196
  };
190
197
  /**
191
- * 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.
192
199
  */
193
200
  5: {
194
201
  message: string;
195
202
  };
196
203
  /**
197
- * 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.
198
205
  */
199
206
  6: {
200
207
  message: string;
201
208
  };
202
209
  /**
203
- * 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.
204
211
  */
205
212
  7: {
206
213
  message: string;
@@ -212,19 +219,19 @@ export declare const DocCompilerError: {
212
219
  message: string;
213
220
  };
214
221
  /**
215
- * `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.
216
223
  */
217
224
  9: {
218
225
  message: string;
219
226
  };
220
227
  /**
221
- * `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.
222
229
  */
223
230
  10: {
224
231
  message: string;
225
232
  };
226
233
  /**
227
- * `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).
228
235
  */
229
236
  11: {
230
237
  message: string;
@@ -249,87 +256,15 @@ export interface CompilerCapabilities {
249
256
  rule_hash_tag: string;
250
257
  }
251
258
  /**
252
- * One op of a postfix-encoded constraint program.
259
+ * Represents different types of signers in the smart account system.
253
260
  */
254
- export type Op = {
255
- tag: "All";
256
- values: readonly [u32];
257
- } | {
258
- tag: "Any";
259
- values: readonly [u32];
260
- } | {
261
- tag: "Not";
262
- values: void;
263
- } | {
264
- tag: "MinSigners";
265
- values: readonly [u32];
266
- } | {
267
- tag: "FnIn";
268
- values: readonly [Array<string>];
269
- } | {
270
- tag: "ArgAddrEq";
271
- values: readonly [u32, string];
272
- } | {
273
- tag: "ArgAddrIsSelf";
274
- values: readonly [u32];
275
- } | {
276
- tag: "ArgSymEq";
277
- values: readonly [u32, string];
278
- } | {
279
- tag: "ArgStrIn";
280
- values: readonly [u32, Array<string>];
281
- } | {
282
- tag: "ArgStrPrefix";
283
- values: readonly [u32, string];
284
- } | {
285
- tag: "ArgBytesEq";
286
- values: readonly [u32, Buffer];
287
- } | {
288
- tag: "ArgI128Eq";
289
- values: readonly [u32, i128];
290
- } | {
291
- tag: "ArgU32Eq";
292
- values: readonly [u32, u32];
293
- } | {
294
- tag: "ArgCount";
295
- values: readonly [u32];
296
- } | {
297
- tag: "LedgerBefore";
298
- values: readonly [u32];
261
+ export type Signer = {
262
+ tag: "Delegated";
263
+ values: readonly [string];
299
264
  } | {
300
- tag: "LedgerAtOrAfter";
301
- values: readonly [u32];
265
+ tag: "External";
266
+ values: readonly [string, Buffer];
302
267
  };
303
- /**
304
- * A postfix-encoded constraint program. The last op produces the root
305
- * verdict.
306
- */
307
- export interface RpnProgram {
308
- /**
309
- * The ops, evaluated left to right.
310
- */
311
- ops: Array<Op>;
312
- /**
313
- * The wire-format version; only [`PROGRAM_VERSION`] validates.
314
- */
315
- version: u32;
316
- }
317
- /**
318
- * What the compiler stores in the interpreter for one `(account, rule)`: the
319
- * program plus the provenance hash of the rule it was compiled from. Sharing
320
- * this `#[contracttype]` between the compiler and the interpreter is what
321
- * keeps install params from ever being a hand-built `ScVal` — both sides
322
- * encode and decode through exactly these types.
323
- */
324
- export interface InstallParams {
325
- /**
326
- * The source rule's `perch_ir::rule_hash`, not the whole document's
327
- * hash (the field keeps its original name). It binds the on-chain
328
- * program to the reviewed rule (provenance for lift/diff).
329
- */
330
- doc_hash: Buffer;
331
- program: RpnProgram;
332
- }
333
268
  /**
334
269
  * A signer credential, shaped like OZ `stellar_accounts::smart_account::Signer`.
335
270
  */
@@ -525,19 +460,126 @@ export declare enum RecoveryAction {
525
460
  Upgrade = 5
526
461
  }
527
462
  /**
528
- * Represents different types of signers in the smart account system.
463
+ * `rule_eval::ZkFactor`.
529
464
  */
530
- export type Signer = {
531
- 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";
532
491
  values: readonly [string];
533
492
  } | {
534
- tag: "External";
535
- 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];
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];
536
568
  };
569
+ /**
570
+ * Exact authorization-entry root in host form.
571
+ */
572
+ export interface StoredAuthRoot {
573
+ contract: string;
574
+ function: string;
575
+ }
537
576
  export interface Client {
538
577
  /**
539
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.
540
- * 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.
541
583
  */
542
584
  limits: (options?: MethodOptions) => Promise<AssembledTransaction<DocLimits>>;
543
585
  /**
@@ -546,7 +588,8 @@ export interface Client {
546
588
  * no auth, no storage. The document must name THIS network (its
547
589
  * `network` string must hash to the chain's network id), so a testnet
548
590
  * document can never compile on mainnet or vice versa. It must also fit
549
- * the document caps ([`Self::limits`]), and every external signer key
591
+ * its caps ([`Self::limits`] for an account document,
592
+ * [`Self::grant_limits`] for a grant document), and every external signer key
550
593
  * must already be its verifier-canonical form: the compiler calls each
551
594
  * named verifier's `batch_canonicalize_key` to check.
552
595
  */
@@ -559,6 +602,13 @@ export interface Client {
559
602
  * produces.
560
603
  */
561
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>>;
562
612
  /**
563
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.
564
614
  * Derive a recovery target (`docs/recovery/spec.md` §7): `source_json`
@@ -577,6 +627,12 @@ export interface Client {
577
627
  action: RecoveryAction;
578
628
  replacements: ReplacementSet;
579
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>>;
580
636
  }
581
637
  export declare class Client extends ContractClient {
582
638
  readonly options: ContractClientOptions;
@@ -595,6 +651,8 @@ export declare class Client extends ContractClient {
595
651
  limits: (json: string) => AssembledTransaction<DocLimits>;
596
652
  compile_doc: (json: string) => AssembledTransaction<Result<CompiledDoc, import("@stellar/stellar-sdk/contract").ErrorMessage>>;
597
653
  capabilities: (json: string) => AssembledTransaction<CompilerCapabilities>;
654
+ grant_limits: (json: string) => AssembledTransaction<DocLimits>;
598
655
  derive_target: (json: string) => AssembledTransaction<Result<DerivedTarget, import("@stellar/stellar-sdk/contract").ErrorMessage>>;
656
+ verifier_registry: (json: string) => AssembledTransaction<string>;
599
657
  };
600
658
  }