prividium 0.20.0 → 0.21.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.
Files changed (104) hide show
  1. package/bin/cli.js +8 -1
  2. package/dist/cli/base-cli.d.ts +5 -0
  3. package/dist/cli/base-cli.js +11 -0
  4. package/dist/cli/commands/config.d.ts +2 -0
  5. package/dist/cli/commands/doctor/clients/browser-auth.d.ts +1 -0
  6. package/dist/cli/commands/doctor/clients/http.d.ts +3 -0
  7. package/dist/cli/commands/doctor/clients/rpc.d.ts +19 -0
  8. package/dist/cli/commands/doctor/clients/wallet-api.d.ts +7 -0
  9. package/dist/cli/commands/doctor/constants.d.ts +1 -0
  10. package/dist/cli/commands/doctor/probes/authentication/authentication.d.ts +4 -0
  11. package/dist/cli/commands/doctor/probes/authentication/wallet-preconditions.d.ts +2 -0
  12. package/dist/cli/commands/doctor/probes/authentication.d.ts +2 -0
  13. package/dist/cli/commands/doctor/probes/bridging/bridging.d.ts +5 -0
  14. package/dist/cli/commands/doctor/probes/bridging.d.ts +2 -0
  15. package/dist/cli/commands/doctor/probes/global/input-validation.d.ts +3 -0
  16. package/dist/cli/commands/doctor/probes/global/reachability.d.ts +5 -0
  17. package/dist/cli/commands/doctor/probes/global.d.ts +2 -0
  18. package/dist/cli/commands/doctor/probes/wallet/authenticated-rpc.d.ts +3 -0
  19. package/dist/cli/commands/doctor/probes/wallet/authorization-and-wallet-rpc.d.ts +5 -0
  20. package/dist/cli/commands/doctor/probes/wallet-api.d.ts +2 -0
  21. package/dist/cli/commands/doctor/probes/wallet.d.ts +2 -0
  22. package/dist/cli/commands/doctor/profile.d.ts +12 -0
  23. package/dist/cli/commands/doctor/report/build.d.ts +2 -0
  24. package/dist/cli/commands/doctor/report/render.d.ts +2 -0
  25. package/dist/cli/commands/doctor/stages.d.ts +2 -0
  26. package/dist/cli/commands/doctor/types.d.ts +90 -0
  27. package/dist/cli/commands/doctor/utils.d.ts +18 -0
  28. package/dist/cli/commands/doctor.d.ts +2 -0
  29. package/dist/cli/commands/proxy.d.ts +2 -0
  30. package/dist/cli/{cli/commands → commands}/proxy.js +1 -3
  31. package/dist/cli/commands/utils/schemas.d.ts +3 -0
  32. package/dist/cli/commands/utils/schemas.js +3 -0
  33. package/dist/cli/commands/utils/show-prividium-header.d.ts +2 -0
  34. package/dist/cli/commands/utils/url-config.d.ts +18 -0
  35. package/dist/cli/commands/verify/account-data-cmd.d.ts +14 -0
  36. package/dist/cli/commands/verify/account-data-cmd.js +102 -0
  37. package/dist/cli/commands/verify/erc20-balance-cmd.d.ts +17 -0
  38. package/dist/cli/commands/verify/erc20-balance-cmd.js +111 -0
  39. package/dist/cli/commands/verify/erc20-supply-cmd.d.ts +16 -0
  40. package/dist/cli/commands/verify/erc20-supply-cmd.js +102 -0
  41. package/dist/cli/commands/verify/utils.d.ts +5 -0
  42. package/dist/cli/commands/verify/utils.js +38 -0
  43. package/dist/cli/commands/verify/verify-workflow.d.ts +8 -0
  44. package/dist/cli/commands/verify/verify-workflow.js +41 -0
  45. package/dist/cli/commands/verify.d.ts +18 -0
  46. package/dist/cli/commands/verify.js +43 -0
  47. package/dist/cli/index.d.ts +3 -0
  48. package/dist/cli/index.js +11 -0
  49. package/dist/cli/server/config-file.d.ts +62 -0
  50. package/dist/cli/server/config-file.js +167 -0
  51. package/dist/cli/server/connection-workflow.d.ts +12 -0
  52. package/dist/cli/server/server.d.ts +28 -0
  53. package/dist/sdk/create-prividium-client.d.ts +1 -1
  54. package/dist/sdk/create-prividium-client.js +1 -1
  55. package/dist/sdk/selective-disclosure/account-properties.d.ts +7 -1
  56. package/dist/sdk/selective-disclosure/account-properties.js +22 -10
  57. package/dist/sdk/selective-disclosure/utils.d.ts +2 -0
  58. package/dist/sdk/selective-disclosure/utils.js +3 -0
  59. package/dist/sdk/selective-disclosure/verify-disclosure.d.ts +35 -12
  60. package/dist/sdk/selective-disclosure/verify-disclosure.js +60 -25
  61. package/dist/tsconfig.cli.tsbuildinfo +1 -0
  62. package/dist/tsconfig.sdk.tsbuildinfo +1 -1
  63. package/package.json +2 -2
  64. package/dist/cli/cli/base-cli.js +0 -9
  65. package/dist/cli/cli/index.js +0 -13
  66. package/dist/cli/cli/server/config-file.js +0 -78
  67. package/dist/cli/src/error-utils.js +0 -73
  68. package/dist/cli/src/memory-storage.js +0 -12
  69. package/dist/cli/src/rpc-error-codes.js +0 -28
  70. package/dist/cli/src/siwe-auth.js +0 -70
  71. package/dist/cli/src/storage.js +0 -142
  72. package/dist/cli/src/types.js +0 -46
  73. package/dist/cli/tsconfig.cli.tsbuildinfo +0 -1
  74. /package/dist/cli/cli/{static/callback.html → callback.html} +0 -0
  75. /package/dist/cli/cli/{static/start.html → start.html} +0 -0
  76. /package/dist/cli/{cli/commands → commands}/config.js +0 -0
  77. /package/dist/cli/{cli/commands → commands}/doctor/clients/browser-auth.js +0 -0
  78. /package/dist/cli/{cli/commands → commands}/doctor/clients/http.js +0 -0
  79. /package/dist/cli/{cli/commands → commands}/doctor/clients/rpc.js +0 -0
  80. /package/dist/cli/{cli/commands → commands}/doctor/clients/wallet-api.js +0 -0
  81. /package/dist/cli/{cli/commands → commands}/doctor/constants.js +0 -0
  82. /package/dist/cli/{cli/commands → commands}/doctor/probes/authentication/authentication.js +0 -0
  83. /package/dist/cli/{cli/commands → commands}/doctor/probes/authentication/wallet-preconditions.js +0 -0
  84. /package/dist/cli/{cli/commands → commands}/doctor/probes/authentication.js +0 -0
  85. /package/dist/cli/{cli/commands → commands}/doctor/probes/bridging/bridging.js +0 -0
  86. /package/dist/cli/{cli/commands → commands}/doctor/probes/bridging.js +0 -0
  87. /package/dist/cli/{cli/commands → commands}/doctor/probes/global/input-validation.js +0 -0
  88. /package/dist/cli/{cli/commands → commands}/doctor/probes/global/reachability.js +0 -0
  89. /package/dist/cli/{cli/commands → commands}/doctor/probes/global.js +0 -0
  90. /package/dist/cli/{cli/commands → commands}/doctor/probes/wallet/authenticated-rpc.js +0 -0
  91. /package/dist/cli/{cli/commands → commands}/doctor/probes/wallet/authorization-and-wallet-rpc.js +0 -0
  92. /package/dist/cli/{cli/commands → commands}/doctor/probes/wallet-api.js +0 -0
  93. /package/dist/cli/{cli/commands → commands}/doctor/probes/wallet.js +0 -0
  94. /package/dist/cli/{cli/commands → commands}/doctor/profile.js +0 -0
  95. /package/dist/cli/{cli/commands → commands}/doctor/report/build.js +0 -0
  96. /package/dist/cli/{cli/commands → commands}/doctor/report/render.js +0 -0
  97. /package/dist/cli/{cli/commands → commands}/doctor/stages.js +0 -0
  98. /package/dist/cli/{cli/commands → commands}/doctor/types.js +0 -0
  99. /package/dist/cli/{cli/commands → commands}/doctor/utils.js +0 -0
  100. /package/dist/cli/{cli/commands → commands}/doctor.js +0 -0
  101. /package/dist/cli/{cli/commands → commands}/utils/show-prividium-header.js +0 -0
  102. /package/dist/cli/{cli/commands → commands}/utils/url-config.js +0 -0
  103. /package/dist/cli/{cli/server → server}/connection-workflow.js +0 -0
  104. /package/dist/cli/{cli/server → server}/server.js +0 -0
package/bin/cli.js CHANGED
@@ -1,2 +1,9 @@
1
1
  #!/usr/bin/env node
2
- import '../dist/cli/cli/index.js';
2
+ import { buildCli } from '../dist/cli/index.js';
3
+
4
+ buildCli()
5
+ .parseAsync(process.argv.slice(2))
6
+ .catch((e) => {
7
+ console.error(e);
8
+ process.exit(1);
9
+ });
@@ -0,0 +1,5 @@
1
+ export declare function createBaseCli(): import("yargs").Argv<{
2
+ configPath: string | undefined;
3
+ }>;
4
+ export type BaseCli = ReturnType<typeof createBaseCli>;
5
+ export type DefCommand = (args: BaseCli) => BaseCli;
@@ -0,0 +1,11 @@
1
+ import yargs from 'yargs';
2
+ export function createBaseCli() {
3
+ return yargs()
4
+ .scriptName('prividium-cli')
5
+ .option('configPath', {
6
+ alias: ['c', 'config-path', 'config'],
7
+ description: 'Path for config file. By default config file is stored under user personal folder',
8
+ type: 'string',
9
+ demandOption: false
10
+ });
11
+ }
@@ -0,0 +1,2 @@
1
+ import type { DefCommand } from '../base-cli.js';
2
+ export declare const addConfig: DefCommand;
@@ -0,0 +1 @@
1
+ export declare function authenticateInBrowser(userPanelBaseUrl: string, callbackPort: number): Promise<string>;
@@ -0,0 +1,3 @@
1
+ import type { z } from 'zod';
2
+ export declare function requireHttpOk(url: URL): Promise<void>;
3
+ export declare function fetchAuthenticatedJson<Schema extends z.ZodTypeAny>(schema: Schema, url: string, token: string): Promise<z.infer<Schema>>;
@@ -0,0 +1,19 @@
1
+ export type RpcResponse = {
2
+ result?: string;
3
+ error?: {
4
+ code: number;
5
+ message: string;
6
+ };
7
+ };
8
+ type RpcCallOptions = {
9
+ method: string;
10
+ params?: unknown[];
11
+ path?: string;
12
+ token?: string;
13
+ };
14
+ export declare function callRpc(apiBaseUrl: string, { method, params, path, token }: RpcCallOptions): Promise<RpcResponse>;
15
+ export declare function requireRpcResult(apiBaseUrl: string, options: RpcCallOptions): Promise<string>;
16
+ export declare function requireForbiddenRpc(apiBaseUrl: string, options: RpcCallOptions): Promise<void>;
17
+ export declare function formatRpcError(method: string, rpcResponse: RpcResponse): string;
18
+ export declare function isForbiddenRpc(rpcResponse: RpcResponse): boolean;
19
+ export {};
@@ -0,0 +1,7 @@
1
+ export declare function fetchWalletRpcToken(apiBaseUrl: string, token: string): Promise<{
2
+ token: string;
3
+ }>;
4
+ export declare function authorizeTransactionProbe(apiBaseUrl: string, token: string, walletAddress: string, nonce: bigint): Promise<{
5
+ activeUntil: string;
6
+ message: string;
7
+ }>;
@@ -0,0 +1 @@
1
+ export declare const DEFAULT_DOCTOR_CALLBACK_PORT = 24101;
@@ -0,0 +1,4 @@
1
+ import type { DoctorContext } from '../../types.js';
2
+ export declare function runBrowserAuthProbe(context: DoctorContext): Promise<void>;
3
+ export declare function runSessionValidationProbe(context: DoctorContext): Promise<void>;
4
+ export declare function runProfileFetchProbe(context: DoctorContext): Promise<void>;
@@ -0,0 +1,2 @@
1
+ import type { DoctorContext, ProbeOutput } from '../../types.js';
2
+ export declare function runWalletPreconditionsProbe(context: DoctorContext): Promise<ProbeOutput>;
@@ -0,0 +1,2 @@
1
+ import type { DoctorStageDefinition } from '../types.js';
2
+ export declare const authenticationStage: DoctorStageDefinition;
@@ -0,0 +1,5 @@
1
+ import type { DoctorContext, ProbeOutput } from '../../types.js';
2
+ export declare function runBridgingL1ChainIdProbe(ctx: DoctorContext, walletAddress: string): Promise<ProbeOutput>;
3
+ export declare function runBridgingBaseTokenProbe(ctx: DoctorContext, walletAddress: string): Promise<ProbeOutput>;
4
+ export declare function runBridgingWethTokenProbe(ctx: DoctorContext, walletAddress: string): Promise<ProbeOutput>;
5
+ export declare function runBridgingOriginChainIdProbe(ctx: DoctorContext, walletAddress: string): Promise<ProbeOutput>;
@@ -0,0 +1,2 @@
1
+ import type { DoctorStageDefinition } from '../types.js';
2
+ export declare function createBridgingStage(walletAddress: string): DoctorStageDefinition;
@@ -0,0 +1,3 @@
1
+ import type { DoctorContext, ProbeOutput } from '../../types.js';
2
+ export declare function runInputValidationProbe(context: DoctorContext): Promise<void>;
3
+ export declare function runHostMismatchProbe(context: DoctorContext): Promise<ProbeOutput | undefined>;
@@ -0,0 +1,5 @@
1
+ import type { DoctorContext, ProbeOutput } from '../../types.js';
2
+ export declare function runCallbackPortProbe(): Promise<void>;
3
+ export declare function runUserPanelReachabilityProbe(context: DoctorContext): Promise<void>;
4
+ export declare function runApiHealthProbe(context: DoctorContext): Promise<ProbeOutput>;
5
+ export declare function runPublicRpcProbe(context: DoctorContext): Promise<ProbeOutput>;
@@ -0,0 +1,2 @@
1
+ import type { DoctorStageDefinition } from '../types.js';
2
+ export declare const globalStage: DoctorStageDefinition;
@@ -0,0 +1,3 @@
1
+ import type { DoctorContext, ProbeOutput } from '../../types.js';
2
+ export declare function runAuthBalanceProbe(context: DoctorContext, walletAddress: string): Promise<ProbeOutput>;
3
+ export declare function runAuthNonceProbe(context: DoctorContext, walletAddress: string): Promise<ProbeOutput>;
@@ -0,0 +1,5 @@
1
+ import type { DoctorContext, ProbeOutput } from '../../types.js';
2
+ export declare function runTransactionAuthorizationProbe(context: DoctorContext, walletAddress: string): Promise<void>;
3
+ export declare function runWalletBalanceProbe(context: DoctorContext, walletAddress: string): Promise<ProbeOutput>;
4
+ export declare function runWalletEthCallRestrictionProbe(context: DoctorContext, walletAddress: string): Promise<void>;
5
+ export declare function runWalletTxCountRestrictionProbe(context: DoctorContext, walletAddress: string): Promise<void>;
@@ -0,0 +1,2 @@
1
+ import type { DoctorStageDefinition } from '../types.js';
2
+ export declare const walletApiStage: DoctorStageDefinition;
@@ -0,0 +1,2 @@
1
+ import type { DoctorStageDefinition } from '../types.js';
2
+ export declare function createWalletStage(walletAddress: string, index: number, total: number): DoctorStageDefinition;
@@ -0,0 +1,12 @@
1
+ import { z } from 'zod';
2
+ export declare const profileSchema: z.ZodObject<{
3
+ id: z.ZodString;
4
+ displayName: z.ZodString;
5
+ roles: z.ZodArray<z.ZodObject<{
6
+ roleName: z.ZodString;
7
+ }, z.core.$strip>>;
8
+ wallets: z.ZodArray<z.ZodObject<{
9
+ walletAddress: z.ZodString;
10
+ }, z.core.$strip>>;
11
+ }, z.core.$strip>;
12
+ export type DoctorProfileSchema = typeof profileSchema;
@@ -0,0 +1,2 @@
1
+ import type { DoctorContext, DoctorReport, DoctorStageDefinition } from '../types.js';
2
+ export declare function buildDoctorReport(context: DoctorContext, stages: DoctorStageDefinition[]): DoctorReport;
@@ -0,0 +1,2 @@
1
+ import type { DoctorReport } from '../types.js';
2
+ export declare function printReport(report: DoctorReport): void;
@@ -0,0 +1,2 @@
1
+ import type { DoctorContext, DoctorStageDefinition } from './types.js';
2
+ export declare function executeDoctorStages(context: DoctorContext, stages: DoctorStageDefinition[]): Promise<void>;
@@ -0,0 +1,90 @@
1
+ import type { z } from 'zod';
2
+ import type { sessionSchema } from '../../server/server.js';
3
+ import type { DoctorProfileSchema } from './profile.js';
4
+ export type Options = {
5
+ rpcUrl?: string;
6
+ userPanelUrl?: string;
7
+ configPath?: string;
8
+ };
9
+ export type NormalizedTargets = {
10
+ apiBaseUrl: string;
11
+ userPanelBaseUrl: string;
12
+ };
13
+ export type ReportStatus = 'pass' | 'warn' | 'fail' | 'skip';
14
+ export type ReportValue = {
15
+ label: string;
16
+ value: string;
17
+ inline?: boolean;
18
+ };
19
+ export type ProbeOutput = {
20
+ status?: Exclude<ReportStatus, 'fail' | 'skip'>;
21
+ values?: ReportValue[];
22
+ details?: string[];
23
+ };
24
+ export type ReportContext = {
25
+ authExpiresAt: string;
26
+ roles: string[];
27
+ sessionType: string;
28
+ userDisplayName: string;
29
+ userId: string;
30
+ walletCount: number;
31
+ };
32
+ export type ProbeResult = {
33
+ id: string;
34
+ label: string;
35
+ status: ReportStatus;
36
+ details?: string[];
37
+ values?: ReportValue[];
38
+ section: string;
39
+ };
40
+ export type ReportBlock = {
41
+ type: 'values';
42
+ id: string;
43
+ title: string;
44
+ values: ReportValue[];
45
+ } | {
46
+ type: 'section';
47
+ id: string;
48
+ title: string;
49
+ probes: ProbeResult[];
50
+ };
51
+ export type DoctorReport = {
52
+ status: ReportStatus;
53
+ blocks: ReportBlock[];
54
+ };
55
+ export type AuthenticatedDoctorState = {
56
+ token: string;
57
+ profile: z.infer<DoctorProfileSchema>;
58
+ session: z.infer<typeof sessionSchema>;
59
+ };
60
+ export type DoctorContext = {
61
+ rawRpcUrl: string;
62
+ rawUserPanelUrl: string;
63
+ targets?: NormalizedTargets;
64
+ authState?: AuthenticatedDoctorState;
65
+ reportContext?: ReportContext;
66
+ walletAddresses: string[];
67
+ walletApiAvailable: boolean;
68
+ walletApiPath?: string;
69
+ results: ProbeResult[];
70
+ pendingToken?: string;
71
+ pendingSession?: z.infer<typeof sessionSchema>;
72
+ apiVersion?: string;
73
+ };
74
+ export type DoctorProbeDefinition = {
75
+ id: string;
76
+ label: string;
77
+ progressMessage?: string;
78
+ runIf?: (context: DoctorContext) => {
79
+ run: true;
80
+ } | {
81
+ run: false;
82
+ reason: string;
83
+ };
84
+ run?: (context: DoctorContext) => Promise<ProbeOutput | undefined> | Promise<void>;
85
+ };
86
+ export type DoctorStageDefinition = {
87
+ id: string;
88
+ title: string;
89
+ getProbes: (context: DoctorContext) => DoctorProbeDefinition[];
90
+ };
@@ -0,0 +1,18 @@
1
+ import type { DoctorContext, NormalizedTargets } from './types.js';
2
+ export declare function passed(id: string, reason: string): (ctx: DoctorContext) => {
3
+ run: true;
4
+ } | {
5
+ run: false;
6
+ reason: string;
7
+ };
8
+ export declare function passed(...deps: [string, string][]): (ctx: DoctorContext) => {
9
+ run: true;
10
+ } | {
11
+ run: false;
12
+ reason: string;
13
+ };
14
+ export declare function formatHexQuantity(value: string): string;
15
+ export declare function shortenAddress(address: string): string;
16
+ export declare function getRawReason(status: number, body: string): string;
17
+ export declare function getThrownReason(error: unknown): string;
18
+ export declare function validateAndNormalizeUrls(prividiumRpcUrl: string, userPanelUrl: string): NormalizedTargets;
@@ -0,0 +1,2 @@
1
+ import type { DefCommand } from '../base-cli.js';
2
+ export declare const addDoctor: DefCommand;
@@ -0,0 +1,2 @@
1
+ import type { DefCommand } from '../base-cli.js';
2
+ export declare const addProxy: DefCommand;
@@ -1,10 +1,8 @@
1
1
  import { intro, log, text } from '@clack/prompts';
2
+ import { MemoryStorage, SiweAuth, TokenManager } from '@repo/prividium-sdk/siwe';
2
3
  import color from 'kleur';
3
4
  import { privateKeyToAccount } from 'viem/accounts';
4
5
  import { z } from 'zod';
5
- import { MemoryStorage } from '../../src/memory-storage.js';
6
- import { SiweAuth } from '../../src/siwe-auth.js';
7
- import { TokenManager } from '../../src/storage.js';
8
6
  import { CreationWorkflow } from '../server/connection-workflow.js';
9
7
  import { buildServer } from '../server/server.js';
10
8
  import { showPrividiumHeader } from './utils/show-prividium-header.js';
@@ -0,0 +1,3 @@
1
+ import { z } from 'zod';
2
+ export declare const hexSchema: z.ZodTemplateLiteral<`0x${string}`>;
3
+ export declare const addressSchema: z.ZodTemplateLiteral<`0x${string}`>;
@@ -0,0 +1,3 @@
1
+ import { z } from 'zod';
2
+ export const hexSchema = z.templateLiteral(['0x', z.string().regex(/^[0-9a-fA-F]*$/)]);
3
+ export const addressSchema = z.templateLiteral(['0x', z.string().regex(/^[0-9a-fA-F]{40}$/)]);
@@ -0,0 +1,2 @@
1
+ export declare const HEADER = " .__ .__ .___.__ .__ .__ \n_____________|__|__ _|__| __| _/|__|__ __ _____ ____ | | |__|\n\\____ \\_ __ \\ \\ \\/ / |/ __ | | | | \\/ \\ ______ _/ ___\\| | | |\n| |_> > | \\/ |\\ /| / /_/ | | | | / Y Y \\ /_____/ \\ \\___| |_| |\n| __/|__| |__| \\_/ |__\\____ | |__|____/|__|_| / \\___ >____/__|\n|__| \\/ \\/ \\/ ";
2
+ export declare function showPrividiumHeader(): void;
@@ -0,0 +1,18 @@
1
+ type GatherApiUrlOptions = {
2
+ configPath?: string;
3
+ apiUrl?: string;
4
+ logProvidedUrls?: boolean;
5
+ };
6
+ export declare function gatherApiUrl({ configPath, apiUrl, logProvidedUrls }: GatherApiUrlOptions): Promise<string>;
7
+ type GatherUrlConfigOptions = {
8
+ configPath?: string;
9
+ rpcUrl?: string;
10
+ rpcUrlLabel: string;
11
+ logProvidedUrls?: boolean;
12
+ userPanelUrl?: string;
13
+ };
14
+ export declare function gatherUrlConfig({ configPath, rpcUrl, userPanelUrl, rpcUrlLabel, logProvidedUrls }: GatherUrlConfigOptions): Promise<{
15
+ prividiumRpcUrl: string;
16
+ userPanelUrl: string;
17
+ }>;
18
+ export {};
@@ -0,0 +1,14 @@
1
+ import type { VerifyDefCommand } from '../verify.js';
2
+ type Opts = {
3
+ address: string;
4
+ l1Rpc?: string;
5
+ apiUrl?: string;
6
+ blockNumber: string;
7
+ diamondAddress?: string;
8
+ configPath?: string;
9
+ expectedBytecode?: string;
10
+ verbose: boolean;
11
+ };
12
+ export declare function verifyAccountData(opts: Opts): Promise<void>;
13
+ export declare const addVerifyAccountDataCmd: VerifyDefCommand;
14
+ export {};
@@ -0,0 +1,102 @@
1
+ import { selectiveDisclosureActions, verifyAccountPropertiesProof } from '@repo/prividium-sdk';
2
+ import { createPublicClient, getAddress, http } from 'viem';
3
+ import { ConfigFile } from '../../server/config-file.js';
4
+ import { addressSchema } from '../utils/schemas.js';
5
+ import { parseBlockNumber } from './utils.js';
6
+ import { VerifyWorkflow } from './verify-workflow.js';
7
+ export async function verifyAccountData(opts) {
8
+ const wf = new VerifyWorkflow();
9
+ const configFile = new ConfigFile(opts.configPath);
10
+ wf.start();
11
+ const givenAddressParsed = addressSchema.safeParse(opts.address);
12
+ if (!givenAddressParsed.success) {
13
+ wf.error(`Invalid address: ${opts.address}`);
14
+ process.exit(1);
15
+ }
16
+ if (opts.diamondAddress && !addressSchema.safeParse(opts.diamondAddress).success) {
17
+ wf.error(`Invalid diamond address: ${opts.diamondAddress}`);
18
+ process.exit(1);
19
+ }
20
+ const givenAddress = getAddress(givenAddressParsed.data);
21
+ try {
22
+ const { l1RpcUrl, diamondAddress, apiUrl } = await configFile.readAndUpdatedRequiredFields({
23
+ apiUrl: opts.apiUrl,
24
+ l1RpcUrl: opts.l1Rpc,
25
+ diamondAddress: opts.diamondAddress
26
+ });
27
+ const prividiumRpcUrl = new URL('/rpc', apiUrl).toString();
28
+ const l1Client = createPublicClient({ transport: http(l1RpcUrl) });
29
+ const prividiumRpc = createPublicClient({ transport: http(prividiumRpcUrl) }).extend(selectiveDisclosureActions);
30
+ const disclosure = await wf
31
+ .step('Gathering proofs', 'Proofs received ✅', () => prividiumRpc.accountDataDisclosure(givenAddress, parseBlockNumber(opts.blockNumber)))
32
+ .catch((e) => {
33
+ const detail = e instanceof Error ? e.message : 'unexpected error';
34
+ wf.error(`Error fetching proofs: ${detail}`);
35
+ process.exit(1);
36
+ });
37
+ if (opts.verbose) {
38
+ wf.message(JSON.stringify(disclosure, null, 2));
39
+ }
40
+ const expectedBytecode = opts.expectedBytecode ? opts.expectedBytecode : undefined;
41
+ const res = await wf
42
+ .step('Verifying proofs', 'Proofs verified ✅', () => verifyAccountPropertiesProof(disclosure, l1Client, getAddress(diamondAddress), expectedBytecode, givenAddress))
43
+ .catch((e) => {
44
+ const detail = e instanceof Error ? e.message : 'unexpected error';
45
+ wf.error(`Unexpected error verifying proofs: ${detail}`);
46
+ process.exit(1);
47
+ });
48
+ if (res.success) {
49
+ [
50
+ `Address: ${getAddress(disclosure.address)}`,
51
+ `Balance: ${disclosure.accountProperties.balance}`,
52
+ `Nonce: ${disclosure.accountProperties.nonce}`,
53
+ `Bytecode: ${disclosure.bytecode}`
54
+ ].forEach((msg) => {
55
+ wf.message(msg);
56
+ });
57
+ wf.success('Ok!');
58
+ }
59
+ else {
60
+ wf.error(`Verification failed: ${res.errorMsg}`);
61
+ process.exit(1);
62
+ }
63
+ }
64
+ catch (e) {
65
+ if (typeof e === 'object' && e && 'message' in e && typeof e.message === 'string') {
66
+ wf.error(e.message);
67
+ }
68
+ else {
69
+ wf.error('Unexpected error');
70
+ }
71
+ process.exit(1);
72
+ }
73
+ }
74
+ export const addVerifyAccountDataCmd = (cli) => cli.command('account-data <address>', 'Verify account data (balance, nonce, bytecode) using proofs from L1', (yargs) => yargs
75
+ .positional('address', {
76
+ description: 'Address of the account to verify',
77
+ type: 'string',
78
+ demandOption: true
79
+ })
80
+ .option('expectedBytecode', {
81
+ alias: ['expected-bytecode', 'bytecode'],
82
+ description: 'Expected contract bytecode (hex). When provided, the verifier checks that the disclosed bytecode hash matches this value.',
83
+ demandOption: false,
84
+ type: 'string'
85
+ })
86
+ .option('verbose', {
87
+ alias: ['v'],
88
+ description: 'Verbose',
89
+ type: 'boolean',
90
+ default: false
91
+ }), async (yargs) => {
92
+ await verifyAccountData({
93
+ address: yargs.address,
94
+ l1Rpc: yargs.l1Rpc,
95
+ apiUrl: yargs.apiUrl,
96
+ blockNumber: yargs.blockNumber,
97
+ diamondAddress: yargs.diamondAddress,
98
+ configPath: yargs.configPath,
99
+ expectedBytecode: yargs.expectedBytecode,
100
+ verbose: yargs.verbose
101
+ });
102
+ });
@@ -0,0 +1,17 @@
1
+ import type { VerifyDefCommand } from '../verify.js';
2
+ type Opts = {
3
+ tokenAddr: string;
4
+ holderAddr: string;
5
+ l1Rpc?: string;
6
+ zkSyncOsRpc?: string;
7
+ apiUrl?: string;
8
+ blockNumber: string;
9
+ diamondAddress?: string;
10
+ bytecodesFile?: string;
11
+ bytecodes: string[];
12
+ configPath?: string;
13
+ verbose: boolean;
14
+ };
15
+ export declare function erc20BalanceCmd(opts: Opts): Promise<void>;
16
+ export declare const addErc20BalanceCmd: VerifyDefCommand;
17
+ export {};
@@ -0,0 +1,111 @@
1
+ import { selectiveDisclosureActions, verifyEthCallDisclosure } from '@repo/prividium-sdk';
2
+ import { createPublicClient, getAddress, hexToBigInt, http } from 'viem';
3
+ import { ConfigFile } from '../../server/config-file.js';
4
+ import { loadBytecodes, parseBlockNumber } from './utils.js';
5
+ import { VerifyWorkflow } from './verify-workflow.js';
6
+ export async function erc20BalanceCmd(opts) {
7
+ const wf = new VerifyWorkflow();
8
+ const configFile = new ConfigFile(opts.configPath);
9
+ wf.start();
10
+ try {
11
+ const bytecodes = loadBytecodes(opts.bytecodesFile, opts.bytecodes);
12
+ const { apiUrl, l1RpcUrl, localZksyncOsRpcUrl, diamondAddress } = await configFile.readAndUpdatedRequiredFields({
13
+ apiUrl: opts.apiUrl,
14
+ l1RpcUrl: opts.l1Rpc,
15
+ localZksyncOsRpcUrl: opts.zkSyncOsRpc,
16
+ diamondAddress: opts.diamondAddress
17
+ });
18
+ const l2RpcUrl = localZksyncOsRpcUrl;
19
+ const prividiumRpcUrl = new URL('/rpc', apiUrl).toString();
20
+ const checkedTokenAddr = getAddress(opts.tokenAddr);
21
+ const checkedHolderAddr = getAddress(opts.holderAddr);
22
+ const l1Client = createPublicClient({ transport: http(l1RpcUrl) });
23
+ const l2Client = createPublicClient({ transport: http(l2RpcUrl) });
24
+ const prividiumRpc = createPublicClient({ transport: http(prividiumRpcUrl) }).extend(selectiveDisclosureActions);
25
+ const disclosure = await wf
26
+ .step('Gathering proofs', 'Proofs fetched ✅', () => prividiumRpc.tokenBalanceDisclosure(checkedTokenAddr, checkedHolderAddr, parseBlockNumber(opts.blockNumber)))
27
+ .catch((e) => {
28
+ const detail = e instanceof Error ? e.message : 'unexpected error';
29
+ wf.error(`Error fetching proofs: ${detail}`);
30
+ process.exit(1);
31
+ });
32
+ if (opts.verbose) {
33
+ wf.message(JSON.stringify(disclosure, null, 2));
34
+ }
35
+ const res = await wf
36
+ .step('Verifying proofs', 'Proofs verified ✅', () => verifyEthCallDisclosure({
37
+ disclosure,
38
+ l1Client,
39
+ l2Client,
40
+ diamondAddress: getAddress(diamondAddress),
41
+ contractBytecodes: bytecodes,
42
+ batchNumber: disclosure.batchNumber
43
+ }))
44
+ .catch((e) => {
45
+ const detail = e instanceof Error ? e.message : 'unexpected error';
46
+ wf.error(`Verification failed: ${detail}`);
47
+ process.exit(1);
48
+ });
49
+ if (res.success) {
50
+ wf.success(`Balance: ${hexToBigInt(disclosure.result)}`);
51
+ }
52
+ else {
53
+ wf.error(`Verification failed: ${res.errorMsg}`);
54
+ process.exit(1);
55
+ }
56
+ }
57
+ catch (e) {
58
+ if (typeof e === 'object' && e && 'message' in e && typeof e.message === 'string') {
59
+ wf.error(e.message);
60
+ }
61
+ else {
62
+ wf.error('Unexpected error');
63
+ }
64
+ process.exit(1);
65
+ }
66
+ }
67
+ export const addErc20BalanceCmd = (cli) => cli.command('erc20-balance <tokenAddr> <holderAddr>', 'Verify an ERC-20 holder balance using proofs from L1', (yargs) => yargs
68
+ .positional('tokenAddr', {
69
+ description: 'Address of the token',
70
+ type: 'string',
71
+ demandOption: true
72
+ })
73
+ .positional('holderAddr', {
74
+ description: 'Address of the token holder to check the balance',
75
+ type: 'string',
76
+ demandOption: true
77
+ })
78
+ .option('bytecodesFile', {
79
+ alias: 'bytecodes-file',
80
+ description: 'JSON file with contracts bytecodes. The file should be a simple object using the addresses as keys with the respective bytecodes as values',
81
+ type: 'string',
82
+ demandOption: false
83
+ })
84
+ .option('bytecodes', {
85
+ alias: ['address-bytecode', 'addressBytecode', 'contractBytecode', 'contract-bytecode'],
86
+ description: "Contract bytecode in '0x<address>:0x<bytecode>' format. Repeat the flag for multiple contracts. Alternatively use --bytecodes-file to supply a JSON map.",
87
+ array: true,
88
+ demandOption: true,
89
+ default: [],
90
+ type: 'string'
91
+ })
92
+ .option('verbose', {
93
+ alias: ['v'],
94
+ description: 'Verbose',
95
+ type: 'boolean',
96
+ default: false
97
+ }), async (yargs) => {
98
+ await erc20BalanceCmd({
99
+ tokenAddr: yargs.tokenAddr,
100
+ holderAddr: yargs.holderAddr,
101
+ blockNumber: yargs.blockNumber,
102
+ diamondAddress: yargs.diamondAddress,
103
+ l1Rpc: yargs.l1Rpc,
104
+ zkSyncOsRpc: yargs.zkSyncOsRpc,
105
+ apiUrl: yargs.apiUrl,
106
+ bytecodesFile: yargs.bytecodesFile,
107
+ bytecodes: yargs.bytecodes,
108
+ configPath: yargs.configPath,
109
+ verbose: yargs.verbose
110
+ });
111
+ });
@@ -0,0 +1,16 @@
1
+ import type { VerifyDefCommand } from '../verify.js';
2
+ type Opts = {
3
+ tokenAddr: string;
4
+ l1Rpc?: string;
5
+ zkSyncOsRpc?: string;
6
+ apiUrl?: string;
7
+ blockNumber: string;
8
+ diamondAddress?: string;
9
+ bytecodesFile?: string;
10
+ bytecodes: string[];
11
+ configPath?: string;
12
+ verbose: boolean;
13
+ };
14
+ export declare function erc20SupplyCmd(opts: Opts): Promise<void>;
15
+ export declare const addErc20SupplyCmd: VerifyDefCommand;
16
+ export {};