@hardkas/l2 0.2.2-alpha → 0.3.0-alpha

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.
package/dist/index.d.ts CHANGED
@@ -10,9 +10,26 @@ interface L2SecurityAssumptions {
10
10
  readonly riskProfile: L2RiskProfile;
11
11
  readonly notes: readonly string[];
12
12
  }
13
+ type L2ProfileSource = "built-in" | "user-config";
14
+ interface L2UserNetworkConfig {
15
+ readonly kind?: "igra" | string;
16
+ readonly chainId: number;
17
+ readonly rpcUrl: string;
18
+ readonly explorerUrl?: string;
19
+ readonly bridgePhase?: L2BridgePhase;
20
+ readonly trustlessExit?: boolean;
21
+ readonly nativeCurrency?: {
22
+ readonly name?: string;
23
+ readonly symbol?: string;
24
+ readonly decimals?: number;
25
+ };
26
+ readonly contracts?: Record<string, string>;
27
+ readonly metadata?: Record<string, unknown>;
28
+ }
13
29
  interface L2NetworkProfile {
14
30
  readonly schema: "hardkas.l2Profile.v1";
15
31
  readonly hardkasVersion: string;
32
+ readonly source: L2ProfileSource;
16
33
  readonly name: string;
17
34
  readonly displayName: string;
18
35
  readonly type: L2NetworkType;
@@ -27,9 +44,18 @@ interface L2NetworkProfile {
27
44
  }
28
45
  declare const BUILTIN_L2_PROFILES: readonly L2NetworkProfile[];
29
46
 
30
- declare function getBuiltInL2Profiles(): readonly L2NetworkProfile[];
31
- declare function listL2Profiles(): readonly L2NetworkProfile[];
32
- declare function getL2Profile(name: string): L2NetworkProfile | null;
47
+ declare function listL2Profiles(userProfiles?: Record<string, L2UserNetworkConfig>): L2NetworkProfile[];
48
+ declare function getL2Profile(name: string, userProfiles?: Record<string, L2UserNetworkConfig>): L2NetworkProfile | null;
49
+ declare function resolveL2Profile(args: {
50
+ name?: string | undefined;
51
+ userProfiles?: Record<string, L2UserNetworkConfig> | undefined;
52
+ cliOverrides?: {
53
+ url?: string | undefined;
54
+ rpcUrl?: string | undefined;
55
+ chainId?: number | string | undefined;
56
+ [key: string]: unknown;
57
+ } | undefined;
58
+ }): L2NetworkProfile;
33
59
  declare function validateL2Profile(profile: any): {
34
60
  ok: boolean;
35
61
  errors: string[];
@@ -174,4 +200,4 @@ declare function assertValidL2BridgeAssumptions(input: unknown): L2BridgeAssumpt
174
200
  */
175
201
  declare function encodeConstructorArgs(bytecode: string, constructorSignature: string, args: string[]): string;
176
202
 
177
- export { BUILTIN_L2_PROFILES, type EvmCallRequest, EvmJsonRpcClient, type EvmJsonRpcClientOptions, type EvmRpcHealthResult, type EvmTransactionReceiptSummary, type IgraTxSigner, type IgraTxSigningInput, type IgraTxSigningResult, type L2BridgeAssumptions, type L2BridgePhase, type L2NetworkProfile, type L2NetworkType, type L2RiskProfile, type L2SecurityAssumptions, UnsupportedIgraTxSigner, ViemIgraTxSigner, type ViemIgraTxSignerOptions, assertValidL2BridgeAssumptions, assertValidL2Profile, checkEvmRpcHealth, encodeConstructorArgs, formatWeiAsEtherLike, getBuiltInL2Profiles, getL2BridgeAssumptions, getL2Profile, listL2BridgeAssumptions, listL2Profiles, normalizeEvmTransactionReceipt, toHexQuantity, validateL2BridgeAssumptions, validateL2Profile, waitForEvmRpcReady };
203
+ export { BUILTIN_L2_PROFILES, type EvmCallRequest, EvmJsonRpcClient, type EvmJsonRpcClientOptions, type EvmRpcHealthResult, type EvmTransactionReceiptSummary, type IgraTxSigner, type IgraTxSigningInput, type IgraTxSigningResult, type L2BridgeAssumptions, type L2BridgePhase, type L2NetworkProfile, type L2NetworkType, type L2ProfileSource, type L2RiskProfile, type L2SecurityAssumptions, type L2UserNetworkConfig, UnsupportedIgraTxSigner, ViemIgraTxSigner, type ViemIgraTxSignerOptions, assertValidL2BridgeAssumptions, assertValidL2Profile, checkEvmRpcHealth, encodeConstructorArgs, formatWeiAsEtherLike, getL2BridgeAssumptions, getL2Profile, listL2BridgeAssumptions, listL2Profiles, normalizeEvmTransactionReceipt, resolveL2Profile, toHexQuantity, validateL2BridgeAssumptions, validateL2Profile, waitForEvmRpcReady };
package/dist/index.js CHANGED
@@ -4,6 +4,7 @@ var BUILTIN_L2_PROFILES = [
4
4
  {
5
5
  schema: "hardkas.l2Profile.v1",
6
6
  hardkasVersion: HARDKAS_VERSION,
7
+ source: "built-in",
7
8
  name: "igra",
8
9
  displayName: "Igra",
9
10
  type: "evm-based-rollup",
@@ -28,14 +29,75 @@ var BUILTIN_L2_PROFILES = [
28
29
  ];
29
30
 
30
31
  // src/registry.ts
31
- function getBuiltInL2Profiles() {
32
- return BUILTIN_L2_PROFILES;
32
+ import { HARDKAS_VERSION as HARDKAS_VERSION2 } from "@hardkas/artifacts";
33
+ function listL2Profiles(userProfiles) {
34
+ const profiles = [...BUILTIN_L2_PROFILES];
35
+ if (userProfiles) {
36
+ for (const [name, config] of Object.entries(userProfiles)) {
37
+ const existingIndex = profiles.findIndex((p) => p.name === name);
38
+ const profile = mapUserConfigToProfile(name, config);
39
+ if (existingIndex !== -1) {
40
+ profiles[existingIndex] = profile;
41
+ } else {
42
+ profiles.push(profile);
43
+ }
44
+ }
45
+ }
46
+ return profiles;
33
47
  }
34
- function listL2Profiles() {
35
- return BUILTIN_L2_PROFILES;
48
+ function getL2Profile(name, userProfiles) {
49
+ return listL2Profiles(userProfiles).find((p) => p.name === name) || null;
36
50
  }
37
- function getL2Profile(name) {
38
- return listL2Profiles().find((p) => p.name === name) || null;
51
+ function resolveL2Profile(args) {
52
+ const name = args.name || "igra";
53
+ const profile = getL2Profile(name, args.userProfiles);
54
+ if (!profile) {
55
+ const available = listL2Profiles(args.userProfiles).map((p) => `${p.name} (${p.source})`).join(", ");
56
+ throw new Error(`L2 profile '${name}' not found. Available profiles: ${available}`);
57
+ }
58
+ let rpcUrl = args.cliOverrides?.rpcUrl || args.cliOverrides?.url || profile.rpcUrl;
59
+ if (args.cliOverrides?.rpcUrl && args.cliOverrides?.url && args.cliOverrides.rpcUrl !== args.cliOverrides.url) {
60
+ throw new Error("Conflict: Both --rpc-url and --url provided with different values.");
61
+ }
62
+ let chainId = profile.chainId;
63
+ if (args.cliOverrides?.chainId !== void 0) {
64
+ chainId = typeof args.cliOverrides.chainId === "string" ? parseInt(args.cliOverrides.chainId, 10) : args.cliOverrides.chainId;
65
+ if (isNaN(chainId)) {
66
+ throw new Error(`Invalid chainId: ${args.cliOverrides.chainId}`);
67
+ }
68
+ }
69
+ const resolved = {
70
+ ...profile,
71
+ ...rpcUrl ? { rpcUrl } : {},
72
+ ...chainId !== void 0 ? { chainId } : {}
73
+ };
74
+ return assertValidL2Profile(resolved);
75
+ }
76
+ function mapUserConfigToProfile(name, config) {
77
+ const bridgePhase = config.bridgePhase || "pre-zk";
78
+ const trustlessExit = config.trustlessExit ?? false;
79
+ return {
80
+ schema: "hardkas.l2Profile.v1",
81
+ hardkasVersion: HARDKAS_VERSION2,
82
+ source: "user-config",
83
+ name,
84
+ displayName: name,
85
+ type: "evm-based-rollup",
86
+ settlementLayer: "kaspa",
87
+ executionLayer: "evm",
88
+ gasToken: config.nativeCurrency?.symbol || (config.kind === "igra" || !config.kind ? "iKAS" : "ETH"),
89
+ nativeTokenDecimals: config.nativeCurrency?.decimals || 18,
90
+ chainId: config.chainId,
91
+ rpcUrl: config.rpcUrl,
92
+ ...config.explorerUrl ? { explorerUrl: config.explorerUrl } : {},
93
+ security: {
94
+ bridgePhase,
95
+ trustlessExit,
96
+ custodyModel: "User-defined bridge custody.",
97
+ riskProfile: "unknown",
98
+ notes: ["User-defined network from config"]
99
+ }
100
+ };
39
101
  }
40
102
  function validateL2Profile(profile) {
41
103
  const errors = [];
@@ -45,36 +107,10 @@ function validateL2Profile(profile) {
45
107
  if (profile.schema !== "hardkas.l2Profile.v1") {
46
108
  errors.push(`Invalid schema: expected 'hardkas.l2Profile.v1', got '${profile.schema}'`);
47
109
  }
48
- if (typeof profile.hardkasVersion !== "string") {
49
- errors.push("Missing or invalid hardkasVersion");
50
- }
51
- if (!profile.name || typeof profile.name !== "string") {
52
- errors.push("Missing or invalid name");
53
- }
54
- if (profile.type !== "evm-based-rollup") {
55
- errors.push(`Invalid type: expected 'evm-based-rollup', got '${profile.type}'`);
56
- }
57
- if (profile.settlementLayer !== "kaspa") {
58
- errors.push(`Invalid settlementLayer: expected 'kaspa', got '${profile.settlementLayer}'`);
59
- }
60
- if (profile.executionLayer !== "evm") {
61
- errors.push(`Invalid executionLayer: expected 'evm', got '${profile.executionLayer}'`);
62
- }
63
- if (!profile.gasToken || typeof profile.gasToken !== "string") {
64
- errors.push("Missing or invalid gasToken");
65
- }
66
110
  if (profile.security) {
67
- if (profile.security.bridgePhase === "zk") {
68
- } else {
69
- if (profile.security.trustlessExit === true) {
70
- errors.push("Security invariant violation: trustlessExit must be false when bridgePhase is not 'zk'");
71
- }
72
- }
73
- if (!Array.isArray(profile.security.notes) || profile.security.notes.length === 0) {
74
- errors.push("Security notes must not be empty");
111
+ if (profile.security.bridgePhase !== "zk" && profile.security.trustlessExit === true) {
112
+ errors.push(`Security invariant violation: trustlessExit=true is only allowed when bridgePhase='zk'. Current phase: ${profile.security.bridgePhase}`);
75
113
  }
76
- } else {
77
- errors.push("Missing security assumptions");
78
114
  }
79
115
  return {
80
116
  ok: errors.length === 0,
@@ -370,10 +406,10 @@ function normalizeEvmTransactionReceipt(raw) {
370
406
  }
371
407
 
372
408
  // src/bridge.ts
373
- import { HARDKAS_VERSION as HARDKAS_VERSION2 } from "@hardkas/artifacts";
409
+ import { HARDKAS_VERSION as HARDKAS_VERSION3 } from "@hardkas/artifacts";
374
410
  var IGRA_BRIDGE_ASSUMPTIONS = {
375
411
  schema: "hardkas.l2BridgeAssumptions.v1",
376
- hardkasVersion: HARDKAS_VERSION2,
412
+ hardkasVersion: HARDKAS_VERSION3,
377
413
  l2Network: "igra",
378
414
  bridgePhase: "pre-zk",
379
415
  trustlessExit: false,
@@ -457,12 +493,12 @@ export {
457
493
  checkEvmRpcHealth,
458
494
  encodeConstructorArgs,
459
495
  formatWeiAsEtherLike,
460
- getBuiltInL2Profiles,
461
496
  getL2BridgeAssumptions,
462
497
  getL2Profile,
463
498
  listL2BridgeAssumptions,
464
499
  listL2Profiles,
465
500
  normalizeEvmTransactionReceipt,
501
+ resolveL2Profile,
466
502
  toHexQuantity,
467
503
  validateL2BridgeAssumptions,
468
504
  validateL2Profile,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hardkas/l2",
3
- "version": "0.2.2-alpha",
3
+ "version": "0.3.0-alpha",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": "./dist/index.js"
@@ -8,7 +8,7 @@
8
8
  "types": "./dist/index.d.ts",
9
9
  "dependencies": {
10
10
  "viem": "^2.48.8",
11
- "@hardkas/artifacts": "0.2.2-alpha"
11
+ "@hardkas/artifacts": "0.3.0-alpha"
12
12
  },
13
13
  "devDependencies": {
14
14
  "tsup": "^8.3.5",