@stellar-registry/perch-artifacts 0.0.0-stage → 0.2.1

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.
Files changed (51) hide show
  1. package/LICENSE +202 -0
  2. package/README.md +87 -2
  3. package/circuits/Nargo.toml +3 -0
  4. package/circuits/artifacts/perch_zk_recovery.json +104 -0
  5. package/circuits/artifacts/perch_zk_recovery_d24.json +104 -0
  6. package/circuits/manifest.json +101 -0
  7. package/circuits/perch_zk/Nargo.toml +9 -0
  8. package/circuits/perch_zk/src/lib.nr +126 -0
  9. package/circuits/perch_zk/src/tests.nr +145 -0
  10. package/circuits/perch_zk_recovery/Nargo.toml +7 -0
  11. package/circuits/perch_zk_recovery/src/main.nr +34 -0
  12. package/circuits/perch_zk_recovery_d24/Nargo.toml +7 -0
  13. package/circuits/perch_zk_recovery_d24/src/main.nr +38 -0
  14. package/circuits/vendor/poseidon/CHECKSUMS.sha256 +13 -0
  15. package/circuits/vendor/poseidon/LICENSE +201 -0
  16. package/circuits/vendor/poseidon/NOTICE +25 -0
  17. package/circuits/vendor/poseidon/Nargo.toml +7 -0
  18. package/circuits/vendor/poseidon/README.md +28 -0
  19. package/circuits/vendor/poseidon/src/bench.nr +6 -0
  20. package/circuits/vendor/poseidon/src/lib.nr +8 -0
  21. package/circuits/vendor/poseidon/src/oracle_tests.nr +20 -0
  22. package/circuits/vendor/poseidon/src/poseidon/bn254/consts.nr +24965 -0
  23. package/circuits/vendor/poseidon/src/poseidon/bn254/perm.nr +115 -0
  24. package/circuits/vendor/poseidon/src/poseidon/bn254.nr +173 -0
  25. package/circuits/vendor/poseidon/src/poseidon/mod.nr +359 -0
  26. package/circuits/vendor/poseidon/src/poseidon2.nr +98 -0
  27. package/circuits/vendor/poseidon/src/tests.nr +34 -0
  28. package/constants.json +14 -0
  29. package/deployments/pending-registry.json +1 -0
  30. package/deployments/testnet-exercise.json +2469 -0
  31. package/deployments/testnet.json +129 -0
  32. package/dist/cli/derive-id.d.ts +2 -0
  33. package/dist/cli/derive-id.js +17 -0
  34. package/dist/cli/fetch-infra-wasm.d.ts +2 -0
  35. package/dist/cli/fetch-infra-wasm.js +5 -0
  36. package/dist/cli/zk-toolchain.d.ts +2 -0
  37. package/dist/cli/zk-toolchain.js +5 -0
  38. package/dist/derive.d.ts +6 -0
  39. package/dist/derive.js +79 -0
  40. package/dist/index.d.ts +105 -0
  41. package/dist/index.js +31 -0
  42. package/dist/script.d.ts +1 -0
  43. package/dist/script.js +12 -0
  44. package/package.json +54 -4
  45. package/scripts/fetch-infra-wasm.sh +150 -0
  46. package/scripts/zk-toolchain.sh +91 -0
  47. package/vectors/auth-vectors.json +143 -0
  48. package/vectors/diagnostic-events.json +37 -0
  49. package/vectors/eval-vectors.json +2244 -0
  50. package/vectors/rule-hashes.json +60 -0
  51. package/vectors/statement-v2.json +230 -0
@@ -0,0 +1,129 @@
1
+ {
2
+ "schema": 1,
3
+ "network": "testnet",
4
+ "network_passphrase": "Test SDF Network ; September 2015",
5
+ "rpc_url": "https://soroban-testnet.stellar.org",
6
+ "channel": "beta",
7
+ "deployed_at": "2026-10-22T13:41:43Z",
8
+ "deployed_ledger": 5330546,
9
+ "source": {
10
+ "commit": "c135aca277745434f2abf679edd9868c95204b51",
11
+ "dirty": false
12
+ },
13
+ "toolchain": {
14
+ "builder": "scaffold",
15
+ "rustc": "rustc 1.99.1 (58cf8f9c3 2026-10-13)",
16
+ "stellar": "stellar 28.0.0-aha.0 (70667cde89632b363d1c8dfb84ff698cbb646988)",
17
+ "scaffold": "scaffold 0.0.27 (stellar-scaffold-cli-v0.0.27-0-g6f1f06c3e8d2cf82573ec214b20d1550e9ce326b)"
18
+ },
19
+ "registry": {
20
+ "id": "CDZGU4AIND6QRCGAN72I7DCS2EKRZ76JSKYY7KKJR4CG5IR2AMFIBZTM",
21
+ "wasm_hash": "0acc4da2b0b44b70988fe9a3b64b31e7ace166e5a949e9e6846f72c6ce93c055",
22
+ "admin": "GAMPJROHOAW662FINQ4XQOY2ULX5IEGYXCI4SMZYE75EHQBR6PSTJG3M",
23
+ "manager": "GAMPJROHOAW662FINQ4XQOY2ULX5IEGYXCI4SMZYE75EHQBR6PSTJG3M",
24
+ "root": "CAAXJETKPYAATU4HVVQUTE2FFBULNFGZNEOC3MS635U5K3GZLAY2HI4M"
25
+ },
26
+ "zk": {
27
+ "circuit_id": "9e39c41f4f35aad43e64b255dfe3ba13f10e8c9d36d6f56fce23c2d97c0a0b4a",
28
+ "tree_depth": 32,
29
+ "circuit_manifest": "circuits/manifest.json"
30
+ },
31
+ "contracts": {
32
+ "perch-doc-compiler": {
33
+ "version": "0.3.5",
34
+ "wasm": "perch_doc_compiler.wasm",
35
+ "sha256": "2730a7d39d619579bb7873818900fa5f9150d69d49fa1ee3b4a38f61ba768a16",
36
+ "bytes": 109947,
37
+ "tier": 0,
38
+ "pins": {},
39
+ "address": "CAYCPM5O6SGGAZOCCAUJ27CZZ7SMHU4VYSA25ZHDMGKILP4Z5RGF467E"
40
+ },
41
+ "perch-interpreter": {
42
+ "version": "0.1.6",
43
+ "wasm": "perch_interpreter.wasm",
44
+ "sha256": "f884913eba4a9491f8bcf89d1a687381c7c0699b148f98f8dc344e9a6223b26e",
45
+ "bytes": 17999,
46
+ "tier": 0,
47
+ "pins": {},
48
+ "address": "CBOGVUQWY5G7BP7OWEJX3Z5PSZLYJXHM54A7OEMXQQ7ZO4GHHM4WCEAP"
49
+ },
50
+ "perch-spending-limit": {
51
+ "version": "0.1.4",
52
+ "wasm": "perch_spending_limit.wasm",
53
+ "sha256": "8c043dcc24f944d7c3e349fb5fd83cedba4a9124b5791b625bd76b520b0f4a80",
54
+ "bytes": 12923,
55
+ "tier": 0,
56
+ "pins": {},
57
+ "address": "CAG3IDO3FXE2HQVQHRGRBKWGL2IPAA2V6B3UMHES4ZUNS7OEV646HYV5"
58
+ },
59
+ "perch-ed25519-verifier": {
60
+ "version": "10.0.2",
61
+ "wasm": "perch_ed25519_verifier.wasm",
62
+ "sha256": "defdab3434b361272c2461a174b94271a49e67fa0a6714b53689aca32e8d1592",
63
+ "bytes": 1863,
64
+ "tier": 0,
65
+ "pins": {},
66
+ "address": "CC7ZFUIENDZPX3C7R4XTA4LG3PCLJM63UGAFYW5XKN35ACIKHZPEDXOG"
67
+ },
68
+ "perch-webauthn-verifier": {
69
+ "version": "0.1.2",
70
+ "wasm": "perch_webauthn_verifier.wasm",
71
+ "sha256": "f2e1dfce8c496be6d318045bc5a24ac5eb799ada837f92e8032ec953f1994230",
72
+ "bytes": 11825,
73
+ "tier": 0,
74
+ "pins": {},
75
+ "address": "CDEV5YPS5IITPLQPYTKJGWBNZ2YZ7FQZIJNSHUMJRBE4QWYK2IVK4EJT"
76
+ },
77
+ "perch-zk-pool": {
78
+ "version": "0.1.4",
79
+ "wasm": "perch_zk_pool.wasm",
80
+ "sha256": "985660d4a6d6baa31a863158e89b8cbecc37cececd7104382172a1805b7289d5",
81
+ "bytes": 47959,
82
+ "tier": 0,
83
+ "pins": {},
84
+ "address": "CASXCXSBIG6ECB3LO4LCEW6SZIFHZDTJ3PFOZJK5JI56VKXLSZY6J67P"
85
+ },
86
+ "perch-zk-adapter": {
87
+ "version": "0.1.4",
88
+ "wasm": "perch_zk_adapter.wasm",
89
+ "sha256": "95869bab4b89e5a4306ffe0d7a9e91931a56518ef18b3f61e95df86145dda63e",
90
+ "bytes": 69803,
91
+ "tier": 0,
92
+ "pins": {},
93
+ "address": "CDWVAUSTU2DHBBWANQKGSHCXFK5C46WMUEMWRBOV2LBVXQGK4PGIFBQS"
94
+ },
95
+ "perch-recovery": {
96
+ "version": "0.1.5",
97
+ "wasm": "perch_recovery.wasm",
98
+ "sha256": "daaf09d9f73f6890753572b33a5c41a22c2ebf0e9ce29593e8407ff858844eb8",
99
+ "bytes": 68263,
100
+ "tier": 0,
101
+ "pins": {},
102
+ "address": "CBOFO5KWQKCZ7LBS4LDIYXA6LGZSUSA6JKOHHBBL64KQNZLPGDJ252FT"
103
+ },
104
+ "perch-account": {
105
+ "version": "0.5.1",
106
+ "wasm": "perch_account.wasm",
107
+ "sha256": "2c976bfd98678f3b6fcf5514420a81ef5e5b9fc1c5b6c60ec6f2dd64448479d5",
108
+ "bytes": 70702,
109
+ "tier": 1,
110
+ "pins": {
111
+ "perch-doc-compiler": "2730a7d39d619579bb7873818900fa5f9150d69d49fa1ee3b4a38f61ba768a16",
112
+ "perch-interpreter": "f884913eba4a9491f8bcf89d1a687381c7c0699b148f98f8dc344e9a6223b26e",
113
+ "perch-spending-limit": "8c043dcc24f944d7c3e349fb5fd83cedba4a9124b5791b625bd76b520b0f4a80"
114
+ }
115
+ },
116
+ "perch-account-factory": {
117
+ "version": "0.3.1",
118
+ "wasm": "perch_account_factory.wasm",
119
+ "sha256": "6b434991d983063c92a47ba1573514f46e5c2ecb184d8c654af60a637ccd3fc2",
120
+ "bytes": 4533,
121
+ "tier": 2,
122
+ "pins": {
123
+ "perch-account": "2c976bfd98678f3b6fcf5514420a81ef5e5b9fc1c5b6c60ec6f2dd64448479d5",
124
+ "perch-webauthn-verifier": "f2e1dfce8c496be6d318045bc5a24ac5eb799ada837f92e8032ec953f1994230"
125
+ },
126
+ "address": "CC7QOMXP6IJRBE6APO7FVCBCPJTDHP3USE3XSQF7AAXWSJ2DZWDV3YXK"
127
+ }
128
+ }
129
+ }
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ export {};
@@ -0,0 +1,17 @@
1
+ #!/usr/bin/env node
2
+ // perch-derive-id content <registry-C-id> <wasm-hash-hex> <network-passphrase>
3
+ //
4
+ // deployer(registry, salt = wasm_hash): a `deploy_stateless` address, as
5
+ // crates/perch-derive-id's `content` mode prints it.
6
+ import { contentAddress } from '../derive.js';
7
+ const [mode, registry, hash, passphrase, ...rest] = process.argv.slice(2);
8
+ if (mode !== 'content' || !registry || !hash || passphrase === undefined || rest.length) {
9
+ const usage = 'usage: perch-derive-id content <registry> <wasm-hash-hex> <passphrase>';
10
+ if (mode === '--help' || mode === '-h') {
11
+ console.log(usage);
12
+ process.exit(0);
13
+ }
14
+ console.error(usage);
15
+ process.exit(2);
16
+ }
17
+ console.log(contentAddress(registry, hash, passphrase));
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ export {};
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env node
2
+ // perch-fetch-infra-wasm: scripts/fetch-infra-wasm.sh against this package's
3
+ // deployments/. Outside a perch checkout it fills only --stack.
4
+ import { runScript } from '../script.js';
5
+ runScript('fetch-infra-wasm.sh');
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ export {};
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env node
2
+ // perch-zk-toolchain: scripts/zk-toolchain.sh, installing the pinned nargo and
3
+ // bb under ./target/zk-toolchain (or PERCH_ZK_TOOLCHAIN_DIR).
4
+ import { runScript } from '../script.js';
5
+ runScript('zk-toolchain.sh');
@@ -0,0 +1,6 @@
1
+ /** The 32-byte contract id a `C…` strkey encodes. Throws on a malformed key. */
2
+ export declare function decodeContract(strkey: string): Uint8Array;
3
+ /** `deployer(parent, salt)`: the address the contract `parent` deploys to under `salt`. */
4
+ export declare function deployedAddress(parent: string, salt: Uint8Array, passphrase: string): string;
5
+ /** A `deploy_stateless` address: `deployer(registry, salt = wasm hash)`. */
6
+ export declare function contentAddress(registry: string, wasmHash: string, passphrase: string): string;
package/dist/derive.js ADDED
@@ -0,0 +1,79 @@
1
+ // Offline contract-id derivation, the computation crates/perch-derive-id
2
+ // runs through soroban's `Env`, so the packaged fetch-infra-wasm.sh checks
3
+ // content addresses without a Rust toolchain:
4
+ //
5
+ // id = sha256(HashIdPreimage::ContractId {
6
+ // network_id: sha256(passphrase),
7
+ // preimage: FromAddress { address: deployer, salt } })
8
+ import { createHash } from 'node:crypto';
9
+ const ALPHABET = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ234567';
10
+ const CONTRACT_VERSION = 2 << 3; // strkey version byte for 'C'
11
+ const ENVELOPE_TYPE_CONTRACT_ID = 8;
12
+ const CONTRACT_ID_PREIMAGE_FROM_ADDRESS = 0;
13
+ const SC_ADDRESS_TYPE_CONTRACT = 1;
14
+ const sha256 = (...parts) => {
15
+ const h = createHash('sha256');
16
+ for (const p of parts)
17
+ h.update(p);
18
+ return new Uint8Array(h.digest());
19
+ };
20
+ function crc16(bytes) {
21
+ let crc = 0;
22
+ for (const b of bytes) {
23
+ crc ^= b << 8;
24
+ for (let i = 0; i < 8; i++)
25
+ crc = crc & 0x8000 ? ((crc << 1) ^ 0x1021) & 0xffff : (crc << 1) & 0xffff;
26
+ }
27
+ return crc;
28
+ }
29
+ function encodeContract(id) {
30
+ const crc = crc16(Uint8Array.of(CONTRACT_VERSION, ...id));
31
+ const data = Uint8Array.of(CONTRACT_VERSION, ...id, crc & 0xff, crc >> 8);
32
+ let out = '';
33
+ let bits = 0;
34
+ let acc = 0;
35
+ for (const b of data) {
36
+ acc = (acc << 8) | b;
37
+ bits += 8;
38
+ while (bits >= 5)
39
+ out += ALPHABET[(acc >> (bits -= 5)) & 31];
40
+ }
41
+ return bits ? out + ALPHABET[(acc << (5 - bits)) & 31] : out;
42
+ }
43
+ /** The 32-byte contract id a `C…` strkey encodes. Throws on a malformed key. */
44
+ export function decodeContract(strkey) {
45
+ if (strkey.length !== 56)
46
+ throw new Error(`not a contract strkey: ${strkey}`);
47
+ const data = [];
48
+ let bits = 0;
49
+ let acc = 0;
50
+ for (const c of strkey) {
51
+ const v = ALPHABET.indexOf(c);
52
+ if (v < 0)
53
+ throw new Error(`not a contract strkey: ${strkey}`);
54
+ acc = (acc << 5) | v;
55
+ bits += 5;
56
+ if (bits >= 8)
57
+ data.push((acc >> (bits -= 8)) & 0xff);
58
+ }
59
+ const id = Uint8Array.from(data.slice(1, 33));
60
+ if (data[0] !== CONTRACT_VERSION || encodeContract(id) !== strkey) {
61
+ throw new Error(`not a contract strkey: ${strkey}`);
62
+ }
63
+ return id;
64
+ }
65
+ function parseHash(hex) {
66
+ const h = hex.replace(/^0x/, '');
67
+ if (!/^[0-9a-fA-F]{64}$/.test(h))
68
+ throw new Error(`not a 32-byte hex hash: ${hex}`);
69
+ return Uint8Array.from(Buffer.from(h, 'hex'));
70
+ }
71
+ /** `deployer(parent, salt)`: the address the contract `parent` deploys to under `salt`. */
72
+ export function deployedAddress(parent, salt, passphrase) {
73
+ const u32 = (n) => Uint8Array.of(n >>> 24, (n >>> 16) & 0xff, (n >>> 8) & 0xff, n & 0xff);
74
+ return encodeContract(sha256(u32(ENVELOPE_TYPE_CONTRACT_ID), sha256(new TextEncoder().encode(passphrase)), u32(CONTRACT_ID_PREIMAGE_FROM_ADDRESS), u32(SC_ADDRESS_TYPE_CONTRACT), decodeContract(parent), salt));
75
+ }
76
+ /** A `deploy_stateless` address: `deployer(registry, salt = wasm hash)`. */
77
+ export function contentAddress(registry, wasmHash, passphrase) {
78
+ return deployedAddress(registry, parseHash(wasmHash), passphrase);
79
+ }
@@ -0,0 +1,105 @@
1
+ export { contentAddress, decodeContract, deployedAddress } from './derive.js';
2
+ /** The installed package's directory. */
3
+ export declare const root: string;
4
+ /** Absolute paths to the shipped artifacts. */
5
+ export declare const paths: {
6
+ /** `deployments/<network>.json`, one manifest per network. */
7
+ deployments: string;
8
+ /** The Noir workspace (`nargo compile --workspace` runs here), with `manifest.json` and the compiled `artifacts/`. */
9
+ circuits: string;
10
+ vectors: string;
11
+ constants: string;
12
+ /** The repository's scripts/fetch-infra-wasm.sh (`perch-fetch-infra-wasm`). */
13
+ fetchInfraWasm: string;
14
+ /** The repository's scripts/zk-toolchain.sh (`perch-zk-toolchain`). */
15
+ zkToolchain: string;
16
+ };
17
+ /** The vectors under `vectors/`, each a copy of one in the repository's testdata/. */
18
+ export type VectorName = 'auth-vectors.json' | 'diagnostic-events.json' | 'statement-v2.json' | 'rule-hashes.json' | 'eval-vectors.json';
19
+ export declare const vectorPath: (name: VectorName) => string;
20
+ export declare const deploymentPath: (network: string) => string;
21
+ /** A deployed contract in a deployment manifest. */
22
+ export interface DeployedContract {
23
+ version: string;
24
+ /** sha256 of the deployed wasm. */
25
+ sha256: string;
26
+ /** The content address under the manifest's registry; absent for the
27
+ * account, which is installed for the factory, not deployed. */
28
+ address?: string;
29
+ tier: number;
30
+ bytes: number;
31
+ wasm: string;
32
+ /** sha256 of every contract this one was built against. */
33
+ pins: Record<string, string>;
34
+ }
35
+ /** A deployment manifest (`deployments/<network>.json`, written by scripts/deploy-stack.sh). */
36
+ export interface Deployment {
37
+ schema: number;
38
+ network: string;
39
+ network_passphrase: string;
40
+ rpc_url: string;
41
+ channel: string;
42
+ deployed_at: string;
43
+ /** The first ledger an indexer needs to scan. */
44
+ deployed_ledger: number;
45
+ source: {
46
+ commit: string;
47
+ dirty: boolean;
48
+ };
49
+ toolchain: Record<string, string>;
50
+ registry: {
51
+ id: string;
52
+ wasm_hash: string;
53
+ admin: string;
54
+ manager: string;
55
+ root: string;
56
+ };
57
+ zk: {
58
+ circuit_id: string;
59
+ tree_depth: number;
60
+ circuit_manifest: string;
61
+ };
62
+ contracts: Record<string, DeployedContract>;
63
+ }
64
+ /** The parsed manifest for `network`. */
65
+ export declare const deployment: (network?: string) => Deployment;
66
+ /** `circuits/manifest.json`. Its paths are repository-relative: the
67
+ * `circuits/` ones resolve against {@link root}; the `vk` files are not
68
+ * shipped (the ZK adapter compiles them in). */
69
+ export interface CircuitManifest {
70
+ circuits: Record<string, {
71
+ acir_bytecode_sha256: string;
72
+ artifact: string;
73
+ artifact_sha256: string;
74
+ circuit_size: number;
75
+ depth: number;
76
+ public_inputs: string[];
77
+ vk: string;
78
+ vk_sha256: string;
79
+ }>;
80
+ fixtures: Record<string, {
81
+ action: string;
82
+ proof_sha256: string;
83
+ public_inputs_sha256: string;
84
+ }>;
85
+ /** sha256 of every circuit source file, by repository path. */
86
+ sources: Record<string, string>;
87
+ toolchain: Record<string, string>;
88
+ }
89
+ export declare const circuitManifest: CircuitManifest;
90
+ /** Limits no contract view reports, written from the crates' own constants
91
+ * by crates/integration-tests/tests/artifact_constants.rs. */
92
+ export interface Constants {
93
+ doc_compiler: {
94
+ MAX_DOC_SIGNERS: number;
95
+ MAX_DOC_RULES: number;
96
+ MAX_DOC_CANONICAL_BYTES: number;
97
+ MAX_RULE_NAME_BYTES: number;
98
+ };
99
+ program: {
100
+ PROGRAM_VERSION: number;
101
+ MAX_PROGRAM_LEN: number;
102
+ MAX_STACK_DEPTH: number;
103
+ };
104
+ }
105
+ export declare const constants: Constants;
package/dist/index.js ADDED
@@ -0,0 +1,31 @@
1
+ // Perch's consumable artifacts as files: the deployment manifests, the ZK
2
+ // recovery circuits, the test vectors, and the program and compiler limits.
3
+ // Import a JSON file directly
4
+ // (`@stellar-registry/perch-artifacts/deployments/testnet.json`), or take a
5
+ // path from here for tools that want one on disk.
6
+ import { readFileSync } from 'node:fs';
7
+ import { join } from 'node:path';
8
+ import { fileURLToPath } from 'node:url';
9
+ export { contentAddress, decodeContract, deployedAddress } from './derive.js';
10
+ /** The installed package's directory. */
11
+ export const root = fileURLToPath(new URL('..', import.meta.url));
12
+ const json = (rel) => JSON.parse(readFileSync(join(root, rel), 'utf8'));
13
+ /** Absolute paths to the shipped artifacts. */
14
+ export const paths = {
15
+ /** `deployments/<network>.json`, one manifest per network. */
16
+ deployments: join(root, 'deployments'),
17
+ /** The Noir workspace (`nargo compile --workspace` runs here), with `manifest.json` and the compiled `artifacts/`. */
18
+ circuits: join(root, 'circuits'),
19
+ vectors: join(root, 'vectors'),
20
+ constants: join(root, 'constants.json'),
21
+ /** The repository's scripts/fetch-infra-wasm.sh (`perch-fetch-infra-wasm`). */
22
+ fetchInfraWasm: join(root, 'scripts', 'fetch-infra-wasm.sh'),
23
+ /** The repository's scripts/zk-toolchain.sh (`perch-zk-toolchain`). */
24
+ zkToolchain: join(root, 'scripts', 'zk-toolchain.sh'),
25
+ };
26
+ export const vectorPath = (name) => join(paths.vectors, name);
27
+ export const deploymentPath = (network) => join(paths.deployments, `${network}.json`);
28
+ /** The parsed manifest for `network`. */
29
+ export const deployment = (network = 'testnet') => json(`deployments/${network}.json`);
30
+ export const circuitManifest = json('circuits/manifest.json');
31
+ export const constants = json('constants.json');
@@ -0,0 +1 @@
1
+ export declare function runScript(name: string): never;
package/dist/script.js ADDED
@@ -0,0 +1,12 @@
1
+ // Runs one of the repository scripts this package ships with bash. npm links
2
+ // a bin into node_modules/.bin, where the script would resolve its own
3
+ // directory wrong, so each bin is this wrapper.
4
+ import { spawnSync } from 'node:child_process';
5
+ import { join } from 'node:path';
6
+ import { root } from './index.js';
7
+ export function runScript(name) {
8
+ const run = spawnSync('bash', [join(root, 'scripts', name), ...process.argv.slice(2)], { stdio: 'inherit' });
9
+ if (run.error)
10
+ throw run.error;
11
+ process.exit(run.status ?? 1);
12
+ }
package/package.json CHANGED
@@ -1,6 +1,56 @@
1
1
  {
2
2
  "name": "@stellar-registry/perch-artifacts",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.2.1",
4
+ "description": "Perch's consumable artifacts as files: deployment manifests, the Noir ZK recovery circuits and their manifest, test vectors, document and program limits, and the scripts that fetch the deployed wasm and install the pinned ZK toolchain",
5
+ "license": "Apache-2.0",
6
+ "type": "module",
7
+ "main": "./dist/index.js",
8
+ "types": "./dist/index.d.ts",
9
+ "bin": {
10
+ "perch-derive-id": "./dist/cli/derive-id.js",
11
+ "perch-fetch-infra-wasm": "./dist/cli/fetch-infra-wasm.js",
12
+ "perch-zk-toolchain": "./dist/cli/zk-toolchain.js"
13
+ },
14
+ "exports": {
15
+ ".": {
16
+ "types": "./dist/index.d.ts",
17
+ "import": "./dist/index.js"
18
+ },
19
+ "./constants.json": "./constants.json",
20
+ "./deployments/*": "./deployments/*",
21
+ "./circuits/*": "./circuits/*",
22
+ "./vectors/*": "./vectors/*",
23
+ "./package.json": "./package.json"
24
+ },
25
+ "files": [
26
+ "dist",
27
+ "constants.json",
28
+ "deployments",
29
+ "circuits",
30
+ "vectors",
31
+ "scripts",
32
+ "README.md"
33
+ ],
34
+ "sideEffects": false,
35
+ "publishConfig": {
36
+ "access": "public"
37
+ },
38
+ "scripts": {
39
+ "build": "tsc -p tsconfig.build.json && node tools/stage.mjs",
40
+ "prepare": "npm run build",
41
+ "prepack": "npm run build",
42
+ "test": "vitest run",
43
+ "check": "tsc --noEmit"
44
+ },
45
+ "devDependencies": {
46
+ "@types/node": "^22.10.0",
47
+ "typescript": "^5.9.3",
48
+ "vitest": "^4.1.7"
49
+ },
50
+ "repository": {
51
+ "type": "git",
52
+ "url": "https://github.com/stellar-registry/perch",
53
+ "directory": "packages/perch-artifacts"
54
+ },
55
+ "gitHead": "6af7622da80309b9c6764f1e05c8a6186ad2e0ad"
56
+ }
@@ -0,0 +1,150 @@
1
+ #!/usr/bin/env bash
2
+ # Populate the build-time pin directories from a deployment manifest
3
+ # (deployments/<network>.json, written by scripts/deploy-stack.sh):
4
+ #
5
+ # crates/perch-smart-account/wasm/ perch-doc-compiler, perch-interpreter,
6
+ # perch-spending-limit
7
+ # crates/perch-account-factory/wasm/ perch-account, perch-webauthn-verifier
8
+ #
9
+ # Each name gets <name>.wasm (git-ignored; only tests read the bytes) and
10
+ # <name>.sha256 (committed, with registry.path: all a build reads, so a plain
11
+ # checkout builds without this script). scripts/check-pins.sh checks the
12
+ # committed pins against the manifest.
13
+ #
14
+ # The registry is not a fetched pin: both crates commit the path they derive
15
+ # it from (wasm/registry.path), and the manifest's registry must be the one
16
+ # that path derives on its network, or a migration
17
+ # deployments/pending-registry.json declares (scripts/manifest-registry.sh).
18
+ # This script refuses any other manifest and never rewrites the path.
19
+ #
20
+ # Each wasm is fetched from the chain by the exact address (or, for the
21
+ # account, the exact wasm hash) the manifest records, and refused unless
22
+ # - its sha256 is the manifest's hash, and
23
+ # - the address is the offline content-address derivation
24
+ # deployer(registry, sha256(wasm)) under the manifest's registry,
25
+ # so a consumer built from this cache pins exactly the deployed contracts.
26
+ # Nothing is resolved by name: the earlier name-salted lookup served a stale
27
+ # pre-cap compiler for months (#95).
28
+ #
29
+ # Usage: scripts/fetch-infra-wasm.sh [--manifest <path>] [--stack <dir>]
30
+ # --manifest default deployments/${STELLAR_NETWORK:-testnet}.json
31
+ # --stack also fetch every manifest contract into <dir> and write
32
+ # <dir>/build.json, so tests/release_stack.rs runs against the
33
+ # deployed bytes; it keeps the manifest's zk circuit, which
34
+ # those bytes compile in
35
+ #
36
+ # Requires the Stellar CLI. After a redeploy, run
37
+ # `cargo test -p perch-integration-tests --test testnet_pins`.
38
+ #
39
+ # The npm package @stellar-registry/perch-artifacts ships this script as
40
+ # `perch-fetch-infra-wasm`, beside a copy of deployments/. There is no crate
41
+ # tree to pin there, so it needs --stack, fills only that, and checks content
42
+ # addresses with the package's own perch-derive-id (a perch checkout uses
43
+ # scripts/derive-id.py).
44
+ set -euo pipefail
45
+
46
+ repo_root="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
47
+ manifest="$repo_root/deployments/${STELLAR_NETWORK:-testnet}.json"
48
+ stack=""
49
+ while [ $# -gt 0 ]; do
50
+ case "$1" in
51
+ --manifest) manifest="$2"; shift 2 ;;
52
+ --stack) stack="$2"; shift 2 ;;
53
+ -h|--help) awk 'NR>1 && /^#/{sub(/^# ?/,""); print; next} NR>1{exit}' "$0"; exit 0 ;;
54
+ *) echo "unknown option: $1" >&2; exit 1 ;;
55
+ esac
56
+ done
57
+ [ -f "$manifest" ] || { echo "error: no manifest at $manifest" >&2; exit 1; }
58
+ # A perch checkout has the crates to pin; the npm package does not.
59
+ checkout=false
60
+ [ -f "$repo_root/Cargo.toml" ] && checkout=true
61
+ $checkout || [ -n "$stack" ] || { echo "error: outside a perch checkout there are no pin caches to fill; pass --stack <dir>" >&2; exit 1; }
62
+ command -v stellar >/dev/null || { echo "error: 'stellar' CLI not found." >&2; exit 1; }
63
+ command -v jq >/dev/null || { echo "error: jq not found" >&2; exit 1; }
64
+
65
+ m() { jq -r "$1" "$manifest"; }
66
+ net=(--rpc-url "$(m .rpc_url)" --network-passphrase "$(m .network_passphrase)")
67
+ registry="$(m .registry.id)"
68
+ [[ "$registry" =~ ^C[A-Z2-7]{55}$ ]] || { echo "error: bad registry id '$registry'" >&2; exit 1; }
69
+
70
+ sha256() { if command -v sha256sum >/dev/null; then sha256sum "$1" | cut -d' ' -f1; else shasum -a 256 "$1" | cut -d' ' -f1; fi; }
71
+ if $checkout; then
72
+ derive() { "$repo_root/scripts/derive-id.py" content "$registry" "$1" "$(m .network_passphrase)"; }
73
+ else
74
+ derive() { node "$repo_root/dist/cli/derive-id.js" content "$registry" "$1" "$(m .network_passphrase)"; }
75
+ fi
76
+
77
+ # The RPC answers a fetch with an occasional 502, so a failed fetch is retried
78
+ # with backoff (2/4/8/16s, STELLAR_FETCH_ATTEMPTS tries in all). Only the
79
+ # network call is retried; a hash mismatch below still fails at once.
80
+ fetch_retry() { # contract-name out-file stellar-contract-fetch-args...
81
+ local name="$1" out="$2" attempts="${STELLAR_FETCH_ATTEMPTS:-5}" try=1 delay=2 err
82
+ shift 2
83
+ err="$(mktemp)"
84
+ until stellar contract fetch "${net[@]}" "$@" --out-file "$out" 2>"$err"; do
85
+ rm -f "$out"
86
+ if [ "$try" -ge "$attempts" ]; then
87
+ echo "error: $name: fetch failed after $try attempts: $(tr -s '\n' ' ' <"$err")" >&2
88
+ rm -f "$err"
89
+ exit 1
90
+ fi
91
+ echo "warning: $name: fetch attempt $try/$attempts failed ($(tr -s '\n' ' ' <"$err")); retrying in ${delay}s" >&2
92
+ sleep "$delay"
93
+ try=$((try + 1)) delay=$((delay * 2))
94
+ done
95
+ rm -f "$err"
96
+ }
97
+
98
+ fetch() { # contract-name out-file
99
+ local name="$1" out="$2" hash addr
100
+ hash="$(jq -r --arg n "$name" '.contracts[$n].sha256 // empty' "$manifest")"
101
+ [ -n "$hash" ] || { echo "error: $name is not in the manifest" >&2; exit 1; }
102
+ addr="$(jq -r --arg n "$name" '.contracts[$n].address // empty' "$manifest")"
103
+ if [ -n "$addr" ]; then
104
+ [ "$(derive "$hash")" = "$addr" ] || {
105
+ echo "error: $name: $addr is not the content address of $hash under $registry" >&2
106
+ exit 1
107
+ }
108
+ fetch_retry "$name" "$out" --id "$addr"
109
+ else
110
+ fetch_retry "$name" "$out" --wasm-hash "$hash"
111
+ fi
112
+ [ "$(sha256 "$out")" = "$hash" ] || {
113
+ echo "error: $name: fetched $(sha256 "$out"), manifest says $hash" >&2
114
+ rm -f "$out"
115
+ exit 1
116
+ }
117
+ printf ' %s %s\n' "$hash" "${out#"$repo_root"/}" >&2
118
+ }
119
+
120
+ pin() { # crate names...
121
+ local dir="$repo_root/crates/$1/wasm" name
122
+ shift
123
+ for name in "$@"; do
124
+ fetch "$name" "$dir/$name.wasm"
125
+ sha256 "$dir/$name.wasm" >"$dir/$name.sha256"
126
+ done
127
+ }
128
+
129
+ if $checkout; then
130
+ state="$("$repo_root/scripts/manifest-registry.sh" --manifest "$manifest")"
131
+ case "$state" in
132
+ pending\ *) echo "warning: pending registry migration (deployments/pending-registry.json): $state" >&2 ;;
133
+ esac
134
+ echo "fetching pins from $(basename "$manifest") (registry $registry) ..." >&2
135
+ pin perch-smart-account perch-doc-compiler perch-interpreter perch-spending-limit
136
+ pin perch-account-factory perch-account perch-webauthn-verifier
137
+ fi
138
+
139
+ if [ -n "$stack" ]; then
140
+ mkdir -p "$stack"
141
+ for name in $(m '.contracts | keys[]'); do
142
+ fetch "$name" "$stack/${name//-/_}.wasm"
143
+ done
144
+ jq '{registry: .registry.id, source, toolchain} + (if .zk then {zk} else {} end) + {
145
+ artifacts: [.contracts | to_entries[] |
146
+ {package: .key, version: .value.version, wasm: (.key | gsub("-"; "_") + ".wasm"),
147
+ sha256: .value.sha256, bytes: .value.bytes, tier: .value.tier,
148
+ pins: (.value.pins // {})}]}' "$manifest" >"$stack/build.json"
149
+ echo "wrote ${stack%/}/build.json" >&2
150
+ fi