prividium 0.12.1 → 0.13.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,6 +1,6 @@
1
1
  import type { Chain } from 'viem';
2
2
  import { type ZodType, z } from 'zod';
3
- import { type AuthorizeTransactionParams, type AuthorizeTransactionResponse, type UserProfile } from './types.js';
3
+ import { type AuthorizeTransactionParams, type AuthorizeTransactionResponse, type ContractAbiResponse, type UserProfile } from './types.js';
4
4
  export declare function rpcUrl(apiUrl: string): string;
5
5
  export declare function walletRpcUrl(apiUrl: string, token: string): string;
6
6
  export declare function buildChainObject(config: {
@@ -17,4 +17,5 @@ export declare function createApiMethods(deps: {
17
17
  getWalletRpcUrl(): Promise<string>;
18
18
  invalidateWalletToken(): Promise<string>;
19
19
  authorizeTransaction(params: AuthorizeTransactionParams): Promise<AuthorizeTransactionResponse>;
20
+ fetchContractAbi(contractAddress: string): Promise<ContractAbiResponse>;
20
21
  };
@@ -1,6 +1,6 @@
1
1
  import { mainnet } from 'viem/chains';
2
2
  import { z } from 'zod';
3
- import { authorizeTransactionResponseSchema, profileSchema } from './types.js';
3
+ import { authorizeTransactionResponseSchema, contractAbiResponseSchema, profileSchema } from './types.js';
4
4
  export function rpcUrl(apiUrl) {
5
5
  return new URL('/rpc', apiUrl).toString();
6
6
  }
@@ -45,6 +45,9 @@ export function createApiMethods(deps) {
45
45
  calldata: params?.calldata ?? '0x',
46
46
  value: params.value?.toString() ?? '0'
47
47
  }));
48
+ },
49
+ async fetchContractAbi(contractAddress) {
50
+ return prividiumApiCall(contractAbiResponseSchema, `${prividiumApiBaseUrl}/api/contracts/${contractAddress}/abi`, 'GET');
48
51
  }
49
52
  };
50
53
  }
@@ -4,5 +4,5 @@ export { createPrividiumChain } from './prividium-chain.js';
4
4
  export { FORBIDDEN_ERROR_CODE, UNAUTHORIZED_ERROR_CODE } from './rpc-error-codes.js';
5
5
  export { LocalStorage, TokenManager } from './storage.js';
6
6
  export { generateRandomState } from './token-utils.js';
7
- export type { AddNetworkParams, PopupOptions, PrividiumChain, PrividiumConfig, Storage, TokenData, UserProfile, UserRole } from './types.js';
7
+ export type { AddNetworkParams, ContractAbiResponse, PopupOptions, PrividiumChain, PrividiumConfig, Storage, TokenData, UserProfile, UserRole } from './types.js';
8
8
  export { AUTH_ERRORS, STORAGE_KEYS } from './types.js';
@@ -96,6 +96,7 @@ export function createPrividiumChain(config) {
96
96
  getWalletRpcUrl: apiMethods.getWalletRpcUrl,
97
97
  invalidateWalletToken: apiMethods.invalidateWalletToken,
98
98
  authorizeTransaction: apiMethods.authorizeTransaction,
99
+ fetchContractAbi: apiMethods.fetchContractAbi,
99
100
  async addNetworkToWallet(params) {
100
101
  if (typeof window === 'undefined' || !window.ethereum) {
101
102
  throw new Error('Wallet not detected. Please install a wallet extension to add network.');
@@ -68,6 +68,21 @@ export declare const authorizeTransactionResponseSchema: z.ZodObject<{
68
68
  activeUntil: z.ZodString;
69
69
  }, z.core.$strip>;
70
70
  export type AuthorizeTransactionResponse = z.infer<typeof authorizeTransactionResponseSchema>;
71
+ export declare const contractAbiResponseSchema: z.ZodObject<{
72
+ contractAddress: z.ZodString;
73
+ name: z.ZodNullable<z.ZodString>;
74
+ abi: z.ZodArray<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
75
+ functions: z.ZodArray<z.ZodObject<{
76
+ selector: z.ZodString;
77
+ signature: z.ZodString;
78
+ name: z.ZodString;
79
+ accessType: z.ZodEnum<{
80
+ read: "read";
81
+ write: "write";
82
+ }>;
83
+ }, z.core.$strip>>;
84
+ }, z.core.$strip>;
85
+ export type ContractAbiResponse = z.infer<typeof contractAbiResponseSchema>;
71
86
  export interface PrividiumChain {
72
87
  chain: Chain;
73
88
  transport: Transport;
@@ -81,6 +96,7 @@ export interface PrividiumChain {
81
96
  invalidateWalletToken(): Promise<string>;
82
97
  authorizeTransaction(params: AuthorizeTransactionParams): Promise<AuthorizeTransactionResponse>;
83
98
  addNetworkToWallet(params?: AddNetworkParams): Promise<void>;
99
+ fetchContractAbi(contractAddress: Address): Promise<ContractAbiResponse>;
84
100
  }
85
101
  export declare const tokenDataSchema: z.ZodObject<{
86
102
  rawToken: z.ZodString;
package/dist/sdk/types.js CHANGED
@@ -14,6 +14,19 @@ export const authorizeTransactionResponseSchema = z.object({
14
14
  message: z.string(),
15
15
  activeUntil: z.string()
16
16
  });
17
+ const methodSelectorSchema = z.string().regex(/^0x[0-9a-fA-F]{8}$/, 'Invalid method selector format');
18
+ const addressSchema = z.string().regex(/^0x[0-9a-fA-F]{40}$/i, 'Invalid address format');
19
+ export const contractAbiResponseSchema = z.object({
20
+ contractAddress: addressSchema,
21
+ name: z.string().nullable(),
22
+ abi: z.array(z.record(z.string(), z.unknown())),
23
+ functions: z.array(z.object({
24
+ selector: methodSelectorSchema,
25
+ signature: z.string(),
26
+ name: z.string(),
27
+ accessType: z.enum(['read', 'write'])
28
+ }))
29
+ });
17
30
  export const tokenDataSchema = z.object({
18
31
  rawToken: z.string(),
19
32
  expiresAt: z.coerce.date()
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "prividium",
3
- "version": "0.12.1",
3
+ "version": "0.13.0",
4
4
  "type": "module",
5
5
  "bin": {
6
6
  "prividium": "bin/cli.js"