@hardkas/l2 0.3.0-alpha → 0.4.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
@@ -44,6 +44,26 @@ interface L2NetworkProfile {
44
44
  }
45
45
  declare const BUILTIN_L2_PROFILES: readonly L2NetworkProfile[];
46
46
 
47
+ interface MetaMaskChainParams {
48
+ chainId: string;
49
+ chainName: string;
50
+ nativeCurrency: {
51
+ name: string;
52
+ symbol: string;
53
+ decimals: number;
54
+ };
55
+ rpcUrls: string[];
56
+ blockExplorerUrls?: string[] | undefined;
57
+ }
58
+ /**
59
+ * Generates the standard wallet_addEthereumChain payload for MetaMask.
60
+ */
61
+ declare function generateAddEthereumChainPayload(profile: L2NetworkProfile): MetaMaskChainParams;
62
+ /**
63
+ * Generates a JavaScript snippet for browser consoles to add the network to MetaMask.
64
+ */
65
+ declare function generateMetaMaskSnippet(profile: L2NetworkProfile): string;
66
+
47
67
  declare function listL2Profiles(userProfiles?: Record<string, L2UserNetworkConfig>): L2NetworkProfile[];
48
68
  declare function getL2Profile(name: string, userProfiles?: Record<string, L2UserNetworkConfig>): L2NetworkProfile | null;
49
69
  declare function resolveL2Profile(args: {
@@ -200,4 +220,4 @@ declare function assertValidL2BridgeAssumptions(input: unknown): L2BridgeAssumpt
200
220
  */
201
221
  declare function encodeConstructorArgs(bytecode: string, constructorSignature: string, args: string[]): string;
202
222
 
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 };
223
+ 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, type MetaMaskChainParams, UnsupportedIgraTxSigner, ViemIgraTxSigner, type ViemIgraTxSignerOptions, assertValidL2BridgeAssumptions, assertValidL2Profile, checkEvmRpcHealth, encodeConstructorArgs, formatWeiAsEtherLike, generateAddEthereumChainPayload, generateMetaMaskSnippet, getL2BridgeAssumptions, resolveL2Profile as getL2NetworkProfile, getL2Profile, listL2BridgeAssumptions, listL2Profiles, normalizeEvmTransactionReceipt, resolveL2Profile, toHexQuantity, validateL2BridgeAssumptions, validateL2Profile, waitForEvmRpcReady };
package/dist/index.js CHANGED
@@ -12,6 +12,8 @@ var BUILTIN_L2_PROFILES = [
12
12
  executionLayer: "evm",
13
13
  gasToken: "iKAS",
14
14
  nativeTokenDecimals: 18,
15
+ chainId: 19416,
16
+ rpcUrl: "http://127.0.0.1:8545",
15
17
  security: {
16
18
  bridgePhase: "pre-zk",
17
19
  trustlessExit: false,
@@ -28,6 +30,36 @@ var BUILTIN_L2_PROFILES = [
28
30
  }
29
31
  ];
30
32
 
33
+ // src/metamask.ts
34
+ function generateAddEthereumChainPayload(profile) {
35
+ if (!profile.chainId) {
36
+ throw new Error(`Profile "${profile.name}" is missing chainId`);
37
+ }
38
+ if (!profile.rpcUrl) {
39
+ throw new Error(`Profile "${profile.name}" is missing rpcUrl`);
40
+ }
41
+ return {
42
+ chainId: `0x${profile.chainId.toString(16)}`,
43
+ chainName: profile.displayName || profile.name,
44
+ nativeCurrency: {
45
+ name: profile.gasToken || "iKAS",
46
+ symbol: profile.gasToken || "iKAS",
47
+ decimals: profile.nativeTokenDecimals || 18
48
+ },
49
+ rpcUrls: [profile.rpcUrl],
50
+ blockExplorerUrls: profile.explorerUrl ? [profile.explorerUrl] : void 0
51
+ };
52
+ }
53
+ function generateMetaMaskSnippet(profile) {
54
+ const payload = generateAddEthereumChainPayload(profile);
55
+ return `await window.ethereum.request({
56
+ method: "wallet_addEthereumChain",
57
+ params: [
58
+ ${JSON.stringify(payload, null, 4).replace(/\n/g, "\n ")}
59
+ ]
60
+ });`;
61
+ }
62
+
31
63
  // src/registry.ts
32
64
  import { HARDKAS_VERSION as HARDKAS_VERSION2 } from "@hardkas/artifacts";
33
65
  function listL2Profiles(userProfiles) {
@@ -493,7 +525,10 @@ export {
493
525
  checkEvmRpcHealth,
494
526
  encodeConstructorArgs,
495
527
  formatWeiAsEtherLike,
528
+ generateAddEthereumChainPayload,
529
+ generateMetaMaskSnippet,
496
530
  getL2BridgeAssumptions,
531
+ resolveL2Profile as getL2NetworkProfile,
497
532
  getL2Profile,
498
533
  listL2BridgeAssumptions,
499
534
  listL2Profiles,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hardkas/l2",
3
- "version": "0.3.0-alpha",
3
+ "version": "0.4.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.3.0-alpha"
11
+ "@hardkas/artifacts": "0.4.0-alpha"
12
12
  },
13
13
  "devDependencies": {
14
14
  "tsup": "^8.3.5",