@bloxchain/sdk 1.0.0-alpha.2 → 1.0.0-alpha.20

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 (129) hide show
  1. package/README.md +376 -376
  2. package/abi/AccountBlox.abi.json +609 -2479
  3. package/abi/BareBlox.abi.json +94 -0
  4. package/abi/BaseStateMachine.abi.json +85 -45
  5. package/abi/CopyBlox.abi.json +1593 -0
  6. package/abi/EngineBlox.abi.json +73 -90
  7. package/abi/GuardController.abi.json +252 -806
  8. package/abi/GuardControllerDefinitions.abi.json +411 -0
  9. package/abi/IDefinition.abi.json +5 -0
  10. package/abi/RoleBlox.abi.json +375 -1590
  11. package/abi/RuntimeRBAC.abi.json +155 -218
  12. package/abi/RuntimeRBACDefinitions.abi.json +179 -0
  13. package/abi/SecureBlox.abi.json +436 -1511
  14. package/abi/SecureOwnable.abi.json +524 -1621
  15. package/abi/SecureOwnableDefinitions.abi.json +5 -0
  16. package/abi/SimpleRWA20.abi.json +478 -1756
  17. package/abi/SimpleRWA20Definitions.abi.json +5 -0
  18. package/abi/SimpleVault.abi.json +648 -2214
  19. package/abi/SimpleVaultDefinitions.abi.json +5 -0
  20. package/dist/abi/AccountBlox.abi.json +3929 -0
  21. package/dist/abi/BareBlox.abi.json +1378 -0
  22. package/dist/abi/BaseStateMachine.abi.json +1213 -1173
  23. package/dist/abi/CopyBlox.abi.json +1593 -0
  24. package/dist/abi/EngineBlox.abi.json +855 -0
  25. package/dist/abi/GuardController.abi.json +2222 -2776
  26. package/dist/abi/GuardControllerDefinitions.abi.json +411 -0
  27. package/dist/abi/IDefinition.abi.json +113 -108
  28. package/dist/abi/RoleBlox.abi.json +2994 -0
  29. package/dist/abi/RuntimeRBAC.abi.json +1540 -1603
  30. package/dist/abi/RuntimeRBACDefinitions.abi.json +381 -0
  31. package/dist/abi/SecureBlox.abi.json +2753 -0
  32. package/dist/abi/SecureOwnable.abi.json +2585 -3682
  33. package/dist/abi/SecureOwnableDefinitions.abi.json +416 -0
  34. package/dist/abi/SimpleRWA20.abi.json +4010 -0
  35. package/dist/abi/SimpleRWA20Definitions.abi.json +196 -0
  36. package/dist/abi/SimpleVault.abi.json +3385 -0
  37. package/dist/abi/SimpleVaultDefinitions.abi.json +274 -0
  38. package/dist/abi.d.ts +11 -0
  39. package/dist/abi.d.ts.map +1 -0
  40. package/dist/abi.js +10 -0
  41. package/dist/abi.js.map +1 -0
  42. package/dist/contracts/{BaseStateMachine.d.ts → core/BaseStateMachine.d.ts} +20 -6
  43. package/dist/contracts/core/BaseStateMachine.d.ts.map +1 -0
  44. package/dist/contracts/{BaseStateMachine.js → core/BaseStateMachine.js} +88 -38
  45. package/dist/contracts/core/BaseStateMachine.js.map +1 -0
  46. package/dist/contracts/{GuardController.d.ts → core/GuardController.d.ts} +22 -15
  47. package/dist/contracts/core/GuardController.d.ts.map +1 -0
  48. package/dist/contracts/{GuardController.js → core/GuardController.js} +19 -21
  49. package/dist/contracts/core/GuardController.js.map +1 -0
  50. package/dist/contracts/core/RuntimeRBAC.d.ts +27 -0
  51. package/dist/contracts/core/RuntimeRBAC.d.ts.map +1 -0
  52. package/dist/contracts/core/RuntimeRBAC.js +33 -0
  53. package/dist/contracts/core/RuntimeRBAC.js.map +1 -0
  54. package/dist/contracts/{SecureOwnable.d.ts → core/SecureOwnable.d.ts} +5 -15
  55. package/dist/contracts/core/SecureOwnable.d.ts.map +1 -0
  56. package/dist/contracts/{SecureOwnable.js → core/SecureOwnable.js} +4 -23
  57. package/dist/contracts/core/SecureOwnable.js.map +1 -0
  58. package/dist/index.d.ts +8 -7
  59. package/dist/index.d.ts.map +1 -1
  60. package/dist/index.js +6 -6
  61. package/dist/index.js.map +1 -1
  62. package/dist/interfaces/base.index.d.ts +10 -2
  63. package/dist/interfaces/base.index.d.ts.map +1 -1
  64. package/dist/interfaces/base.state.machine.index.d.ts +3 -2
  65. package/dist/interfaces/base.state.machine.index.d.ts.map +1 -1
  66. package/dist/interfaces/core.access.index.d.ts +2 -16
  67. package/dist/interfaces/core.access.index.d.ts.map +1 -1
  68. package/dist/interfaces/core.execution.index.d.ts +8 -11
  69. package/dist/interfaces/core.execution.index.d.ts.map +1 -1
  70. package/dist/interfaces/core.security.index.d.ts +1 -4
  71. package/dist/interfaces/core.security.index.d.ts.map +1 -1
  72. package/dist/lib/Definition.d.ts.map +1 -1
  73. package/dist/lib/Definition.js +1 -0
  74. package/dist/lib/Definition.js.map +1 -1
  75. package/dist/lib/EngineBlox.d.ts +16 -49
  76. package/dist/lib/EngineBlox.d.ts.map +1 -1
  77. package/dist/lib/EngineBlox.js +20 -108
  78. package/dist/lib/EngineBlox.js.map +1 -1
  79. package/dist/lib/definitions/GuardControllerDefinitions.d.ts +34 -7
  80. package/dist/lib/definitions/GuardControllerDefinitions.d.ts.map +1 -1
  81. package/dist/lib/definitions/GuardControllerDefinitions.js +62 -10
  82. package/dist/lib/definitions/GuardControllerDefinitions.js.map +1 -1
  83. package/dist/lib/definitions/RuntimeRBACDefinitions.d.ts +48 -7
  84. package/dist/lib/definitions/RuntimeRBACDefinitions.d.ts.map +1 -1
  85. package/dist/lib/definitions/RuntimeRBACDefinitions.js +73 -10
  86. package/dist/lib/definitions/RuntimeRBACDefinitions.js.map +1 -1
  87. package/dist/lib/definitions/SecureOwnableDefinitions.d.ts +12 -7
  88. package/dist/lib/definitions/SecureOwnableDefinitions.d.ts.map +1 -1
  89. package/dist/lib/definitions/SecureOwnableDefinitions.js +25 -9
  90. package/dist/lib/definitions/SecureOwnableDefinitions.js.map +1 -1
  91. package/dist/lib/definitions/index.d.ts +6 -4
  92. package/dist/lib/definitions/index.d.ts.map +1 -1
  93. package/dist/lib/definitions/index.js +5 -4
  94. package/dist/lib/definitions/index.js.map +1 -1
  95. package/dist/types/base.state.machine.index.d.ts +0 -2
  96. package/dist/types/base.state.machine.index.d.ts.map +1 -1
  97. package/dist/types/base.state.machine.index.js +1 -3
  98. package/dist/types/base.state.machine.index.js.map +1 -1
  99. package/dist/types/core.execution.index.d.ts +1 -0
  100. package/dist/types/core.execution.index.d.ts.map +1 -1
  101. package/dist/types/core.execution.index.js +1 -0
  102. package/dist/types/core.execution.index.js.map +1 -1
  103. package/dist/types/core.security.index.d.ts.map +1 -1
  104. package/dist/types/core.security.index.js +2 -2
  105. package/dist/types/core.security.index.js.map +1 -1
  106. package/dist/types/definition.index.d.ts +2 -0
  107. package/dist/types/definition.index.d.ts.map +1 -1
  108. package/dist/types/definition.index.js.map +1 -1
  109. package/dist/utils/contract-errors.d.ts +125 -6
  110. package/dist/utils/contract-errors.d.ts.map +1 -1
  111. package/dist/utils/contract-errors.js +375 -107
  112. package/dist/utils/contract-errors.js.map +1 -1
  113. package/dist/utils/interface-ids.js +8 -8
  114. package/dist/utils/interface-ids.js.map +1 -1
  115. package/dist/utils/metaTx/metaTransaction.d.ts +103 -7
  116. package/dist/utils/metaTx/metaTransaction.d.ts.map +1 -1
  117. package/dist/utils/metaTx/metaTransaction.js +136 -25
  118. package/dist/utils/metaTx/metaTransaction.js.map +1 -1
  119. package/package.json +10 -6
  120. package/dist/contracts/BaseStateMachine.d.ts.map +0 -1
  121. package/dist/contracts/BaseStateMachine.js.map +0 -1
  122. package/dist/contracts/GuardController.d.ts.map +0 -1
  123. package/dist/contracts/GuardController.js.map +0 -1
  124. package/dist/contracts/RuntimeRBAC.d.ts +0 -54
  125. package/dist/contracts/RuntimeRBAC.d.ts.map +0 -1
  126. package/dist/contracts/RuntimeRBAC.js +0 -58
  127. package/dist/contracts/RuntimeRBAC.js.map +0 -1
  128. package/dist/contracts/SecureOwnable.d.ts.map +0 -1
  129. package/dist/contracts/SecureOwnable.js.map +0 -1
@@ -1,4 +1,4 @@
1
- import { Address, Hex, PublicClient } from 'viem';
1
+ import { Address, Hex } from 'viem';
2
2
  import { TxAction } from '../types/lib.index';
3
3
  import { Uint16Bitmap } from '../utils/bitmap';
4
4
  /**
@@ -15,7 +15,7 @@ import { Uint16Bitmap } from '../utils/bitmap';
15
15
  *
16
16
  * // Access constants
17
17
  * const protocolName = EngineBlox.PROTOCOL_NAME_HASH;
18
- * const version = `${EngineBlox.VERSION_MAJOR}.${EngineBlox.VERSION_MINOR}.${EngineBlox.VERSION_PATCH}`;
18
+ * const version = EngineBlox.VERSION;
19
19
  *
20
20
  * // Use pure functions
21
21
  * const signer = EngineBlox.recoverSigner(messageHash, signature);
@@ -30,17 +30,14 @@ export declare class EngineBlox {
30
30
  */
31
31
  static readonly PROTOCOL_NAME_HASH: Hex;
32
32
  /**
33
- * Major version number
33
+ * Protocol version string (semver, e.g. "1.0.0"). Matches EngineBlox.sol VERSION and EIP-712 domain version.
34
34
  */
35
- static readonly VERSION_MAJOR: number;
35
+ static readonly VERSION: string;
36
36
  /**
37
- * Minor version number
37
+ * Maximum bytes retained from callee returndata on guarded execution (`EngineBlox.executeTransaction` path).
38
+ * Matches `EngineBlox.MAX_RESULT_PREVIEW_BYTES` (32 KiB).
38
39
  */
39
- static readonly VERSION_MINOR: number;
40
- /**
41
- * Patch version number
42
- */
43
- static readonly VERSION_PATCH: number;
40
+ static readonly MAX_RESULT_PREVIEW_BYTES: bigint;
44
41
  /**
45
42
  * Native token transfer selector (reserved signature for simple ETH transfers)
46
43
  * Computed as bytes4(keccak256("__bloxchain_native_transfer__()"))
@@ -51,14 +48,14 @@ export declare class EngineBlox {
51
48
  */
52
49
  static readonly NATIVE_TRANSFER_OPERATION: Hex;
53
50
  /**
54
- * Payment update selector (reserved signature for payment detail updates)
55
- * Computed as bytes4(keccak256("__bloxchain_update_payment__()"))
51
+ * Pseudo-selector: whitelist key for attached payment recipients (native + ERC20 payout addresses).
52
+ * Matches `ATTACHED_PAYMENT_RECIPIENT_SELECTOR` in EngineBlox.sol.
56
53
  */
57
- static readonly UPDATE_PAYMENT_SELECTOR: Hex;
54
+ static readonly ATTACHED_PAYMENT_RECIPIENT_SELECTOR: Hex;
58
55
  /**
59
- * Payment update operation type hash
56
+ * Standard IERC20 `transfer(address,uint256)` whitelist key for token contracts in attached ERC20 payments.
60
57
  */
61
- static readonly UPDATE_PAYMENT_OPERATION: Hex;
58
+ static readonly ERC20_TRANSFER_SELECTOR: Hex;
62
59
  /**
63
60
  * Owner role hash
64
61
  */
@@ -72,43 +69,13 @@ export declare class EngineBlox {
72
69
  */
73
70
  static readonly RECOVERY_ROLE: Hex;
74
71
  /**
75
- * @dev Recovers the signer address from a message hash and signature
76
- * @param messageHash The hash of the message that was signed (bytes32)
77
- * @param signature The signature to recover the address from (65 bytes)
72
+ * @dev Recovers the signer address from the EIP-712 digest and signature (standard EIP-712; no EIP-191 prefix).
73
+ * @param messageHash The EIP-712 digest (keccak256("\x19\x01" || domainSeparator || structHash))
74
+ * @param signature The signature (65 bytes)
78
75
  * @returns Promise that resolves to the address of the signer
79
- * @throws Error if signature is invalid or recovery fails
80
- *
81
- * @notice This matches the contract's recoverSigner function which uses
82
- * messageHash.toEthSignedMessageHash() to convert to EIP-191 format
83
- *
84
- * @example
85
- * ```typescript
86
- * const messageHash = "0x1234...";
87
- * const signature = "0xabcd...";
88
- * const signer = await EngineBlox.recoverSigner(messageHash, signature);
89
- * ```
76
+ * @notice Matches the contract's recoverSigner which uses ecrecover(messageHash, v, r, s) on the raw digest.
90
77
  */
91
78
  static recoverSigner(messageHash: Hex, signature: Hex): Promise<Address>;
92
- /**
93
- * @dev Checks if a function selector exists in a contract's bytecode
94
- * @param client PublicClient instance for reading contract bytecode
95
- * @param contractAddress The address of the contract to check
96
- * @param selector The 4-byte function selector to search for
97
- * @returns Promise that resolves to true if the selector is found in the contract's function selector dispatch table
98
- *
99
- * @notice Searches the first 2KB where function selectors are stored in the dispatch table
100
- * @notice This is a heuristic check - false positives are possible but unlikely
101
- *
102
- * @example
103
- * ```typescript
104
- * const exists = await EngineBlox.selectorExistsInContract(
105
- * publicClient,
106
- * '0x1234...',
107
- * '0xabcd1234'
108
- * );
109
- * ```
110
- */
111
- static selectorExistsInContract(client: PublicClient, contractAddress: Address, selector: Hex): Promise<boolean>;
112
79
  /**
113
80
  * @dev Checks if a TxAction is present in a bitmap
114
81
  * @param bitmap The bitmap to check
@@ -1 +1 @@
1
- {"version":3,"file":"EngineBlox.d.ts","sourceRoot":"","sources":["../../lib/EngineBlox.tsx"],"names":[],"mappings":"AAAA,OAAO,EAA4B,OAAO,EAAE,GAAG,EAAE,YAAY,EAA8B,MAAM,MAAM,CAAC;AACxG,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAC9C,OAAO,EAAE,YAAY,EAAsB,MAAM,iBAAiB,CAAC;AASnE;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,qBAAa,UAAU;IAGrB;;OAEG;IACH,MAAM,CAAC,QAAQ,CAAC,kBAAkB,EAAE,GAAG,CAA0B;IAEjE;;OAEG;IACH,MAAM,CAAC,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAK;IAE1C;;OAEG;IACH,MAAM,CAAC,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAK;IAE1C;;OAEG;IACH,MAAM,CAAC,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAK;IAI1C;;;OAGG;IACH,MAAM,CAAC,QAAQ,CAAC,wBAAwB,EAAE,GAAG,CAEpC;IAET;;OAEG;IACH,MAAM,CAAC,QAAQ,CAAC,yBAAyB,EAAE,GAAG,CAAgC;IAE9E;;;OAGG;IACH,MAAM,CAAC,QAAQ,CAAC,uBAAuB,EAAE,GAAG,CAEnC;IAET;;OAEG;IACH,MAAM,CAAC,QAAQ,CAAC,wBAAwB,EAAE,GAAG,CAA+B;IAI5E;;OAEG;IACH,MAAM,CAAC,QAAQ,CAAC,UAAU,EAAE,GAAG,CAA2B;IAE1D;;OAEG;IACH,MAAM,CAAC,QAAQ,CAAC,gBAAgB,EAAE,GAAG,CAAiC;IAEtE;;OAEG;IACH,MAAM,CAAC,QAAQ,CAAC,aAAa,EAAE,GAAG,CAA8B;IAIhE;;;;;;;;;;;;;;;;OAgBG;WACU,aAAa,CAAC,WAAW,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AAC,wBAAwB,EAAE,GAAG,CAEpC;IAET;;OAEG;IACH,MAAM,CAAC,QAAQ,CAAC,yBAAyB,EAAE,GAAG,CAAgC;IAE9E;;;OAGG;IACH,MAAM,CAAC,QAAQ,CAAC,mCAAmC,EAAE,GAAG,CAE/C;IAET;;OAEG;IACH,MAAM,CAAC,QAAQ,CAAC,uBAAuB,EAAE,GAAG,CAEnC;IAIT;;OAEG;IACH,MAAM,CAAC,QAAQ,CAAC,UAAU,EAAE,GAAG,CAA2B;IAE1D;;OAEG;IACH,MAAM,CAAC,QAAQ,CAAC,gBAAgB,EAAE,GAAG,CAAiC;IAEtE;;OAEG;IACH,MAAM,CAAC,QAAQ,CAAC,aAAa,EAAE,GAAG,CAA8B;IAIhE;;;;;;OAMG;WACU,aAAa,CAAC,WAAW,EAAE,GAAG,EAAE,SAAS,EAAE,GAAG,GAAG,OAAO,CAAC,OAAO,CAAC;IAmB9E;;;;;;;;;;OAUG;IACH,MAAM,CAAC,iBAAiB,CAAC,MAAM,EAAE,YAAY,EAAE,MAAM,EAAE,QAAQ,GAAG,OAAO;IAIzE;;;;;;;;;;OAUG;IACH,MAAM,CAAC,iBAAiB,CAAC,MAAM,EAAE,YAAY,EAAE,MAAM,EAAE,QAAQ,GAAG,YAAY;IAI9E;;;;;;;;;;;;OAYG;IACH,MAAM,CAAC,uBAAuB,CAAC,OAAO,EAAE,QAAQ,EAAE,GAAG,YAAY;IAQjE;;;;;;;;;;OAUG;IACH,MAAM,CAAC,sBAAsB,CAAC,MAAM,EAAE,YAAY,GAAG,QAAQ,EAAE;CAYhE;AAED;;GAEG;AACH,eAAe,UAAU,CAAC"}
@@ -20,7 +20,7 @@ const keccak256 = (str) => {
20
20
  *
21
21
  * // Access constants
22
22
  * const protocolName = EngineBlox.PROTOCOL_NAME_HASH;
23
- * const version = `${EngineBlox.VERSION_MAJOR}.${EngineBlox.VERSION_MINOR}.${EngineBlox.VERSION_PATCH}`;
23
+ * const version = EngineBlox.VERSION;
24
24
  *
25
25
  * // Use pure functions
26
26
  * const signer = EngineBlox.recoverSigner(messageHash, signature);
@@ -32,113 +32,28 @@ const keccak256 = (str) => {
32
32
  export class EngineBlox {
33
33
  // ============ PURE FUNCTIONS ============
34
34
  /**
35
- * @dev Recovers the signer address from a message hash and signature
36
- * @param messageHash The hash of the message that was signed (bytes32)
37
- * @param signature The signature to recover the address from (65 bytes)
35
+ * @dev Recovers the signer address from the EIP-712 digest and signature (standard EIP-712; no EIP-191 prefix).
36
+ * @param messageHash The EIP-712 digest (keccak256("\x19\x01" || domainSeparator || structHash))
37
+ * @param signature The signature (65 bytes)
38
38
  * @returns Promise that resolves to the address of the signer
39
- * @throws Error if signature is invalid or recovery fails
40
- *
41
- * @notice This matches the contract's recoverSigner function which uses
42
- * messageHash.toEthSignedMessageHash() to convert to EIP-191 format
43
- *
44
- * @example
45
- * ```typescript
46
- * const messageHash = "0x1234...";
47
- * const signature = "0xabcd...";
48
- * const signer = await EngineBlox.recoverSigner(messageHash, signature);
49
- * ```
39
+ * @notice Matches the contract's recoverSigner which uses ecrecover(messageHash, v, r, s) on the raw digest.
50
40
  */
51
41
  static async recoverSigner(messageHash, signature) {
52
- // Validate signature length (65 bytes = 130 hex chars + '0x' prefix)
53
42
  if (signature.length !== 132) {
54
- throw new Error(`Invalid signature length: expected 65 bytes (132 hex chars), got ${signature.length - 2} bytes`);
43
+ throw new Error(`Invalid signature length: expected 65 bytes (132 hex chars), got ${(signature.length - 2) / 2} bytes`);
55
44
  }
56
45
  try {
57
- // The contract uses messageHash.toEthSignedMessageHash() which converts to EIP-191 format
58
- // EIP-191 format for 32-byte hash: keccak256("\x19Ethereum Signed Message:\n32" + messageHash)
59
- // We need to create the EIP-191 formatted hash and then recover from it
60
- const prefix = '\x19Ethereum Signed Message:\n32';
61
- const messageHashBytes = Buffer.from(messageHash.slice(2), 'hex');
62
- // Concatenate prefix and hash
63
- const eip191Message = Buffer.concat([
64
- Buffer.from(prefix, 'utf8'),
65
- messageHashBytes
66
- ]);
67
- // Convert Buffer to Uint8Array for viem
68
- const eip191MessageBytes = new Uint8Array(eip191Message);
69
- // Hash the EIP-191 formatted message
70
- const eip191Hash = (await k256(eip191MessageBytes));
71
- // Recover address from the EIP-191 formatted hash
72
- // Note: recoverAddress is async in viem
73
- const recovered = await recoverAddress({
74
- hash: eip191Hash,
75
- signature: signature
46
+ const signer = await recoverAddress({
47
+ hash: messageHash,
48
+ signature
76
49
  });
77
- return recovered;
50
+ return signer;
78
51
  }
79
52
  catch (error) {
80
53
  throw new Error(`Failed to recover signer: ${error instanceof Error ? error.message : 'Unknown error'}`);
81
54
  }
82
55
  }
83
56
  // ============ VIEW FUNCTIONS (No storage access) ============
84
- /**
85
- * @dev Checks if a function selector exists in a contract's bytecode
86
- * @param client PublicClient instance for reading contract bytecode
87
- * @param contractAddress The address of the contract to check
88
- * @param selector The 4-byte function selector to search for
89
- * @returns Promise that resolves to true if the selector is found in the contract's function selector dispatch table
90
- *
91
- * @notice Searches the first 2KB where function selectors are stored in the dispatch table
92
- * @notice This is a heuristic check - false positives are possible but unlikely
93
- *
94
- * @example
95
- * ```typescript
96
- * const exists = await EngineBlox.selectorExistsInContract(
97
- * publicClient,
98
- * '0x1234...',
99
- * '0xabcd1234'
100
- * );
101
- * ```
102
- */
103
- static async selectorExistsInContract(client, contractAddress, selector) {
104
- try {
105
- // Get the contract's bytecode
106
- const code = await client.getCode({ address: contractAddress });
107
- if (!code || code.length < 12) { // Need at least '0x' + PUSH4 (1 byte = 2 hex chars) + selector (4 bytes = 8 hex chars) = 12 chars
108
- return false;
109
- }
110
- // Function selectors are in the dispatch table at the beginning
111
- // Typical dispatch tables are < 2KB even for large contracts
112
- // Searching only this area reduces gas cost and false positives from metadata/data
113
- // 2KB = 2048 bytes = 4096 hex chars (plus '0x' prefix = 4098 total)
114
- const maxSearchBytes = 2048;
115
- const codeHexLength = code.length - 2; // Remove '0x' prefix
116
- const maxSearchHexChars = maxSearchBytes * 2; // Each byte is 2 hex chars
117
- const searchLength = codeHexLength < maxSearchHexChars ? codeHexLength : maxSearchHexChars;
118
- // Convert hex strings for searching (normalize to lowercase)
119
- const codeBytes = code.slice(2).toLowerCase(); // Remove '0x' prefix and normalize
120
- const selectorBytes = selector.slice(2).toLowerCase(); // Remove '0x' and normalize
121
- // Scan for PUSH4 opcode (0x63 = "63" in hex) with 1-byte sliding window
122
- // PUSH4 opcode is followed by 4 bytes (8 hex chars) which is the function selector
123
- // Function selectors in EVM bytecode are emitted as PUSH4 <selector> instructions
124
- // These can start at any byte offset, not just 4-byte-aligned positions
125
- for (let i = 0; i + 10 <= searchLength; i += 2) { // i += 2 because each byte is 2 hex chars
126
- // Check if current byte is PUSH4 opcode (0x63 = "63" in hex)
127
- if (codeBytes.slice(i, i + 2) === '63') {
128
- // Check if the next 8 hex chars (4 bytes) match the selector
129
- const candidate = codeBytes.slice(i + 2, i + 10);
130
- if (candidate === selectorBytes) {
131
- return true;
132
- }
133
- }
134
- }
135
- return false;
136
- }
137
- catch (error) {
138
- // If we can't read the bytecode, return false
139
- return false;
140
- }
141
- }
142
57
  // ============ BITMAP HELPER FUNCTIONS ============
143
58
  /**
144
59
  * @dev Checks if a TxAction is present in a bitmap
@@ -216,17 +131,14 @@ export class EngineBlox {
216
131
  */
217
132
  EngineBlox.PROTOCOL_NAME_HASH = keccak256("Bloxchain");
218
133
  /**
219
- * Major version number
220
- */
221
- EngineBlox.VERSION_MAJOR = 1;
222
- /**
223
- * Minor version number
134
+ * Protocol version string (semver, e.g. "1.0.0"). Matches EngineBlox.sol VERSION and EIP-712 domain version.
224
135
  */
225
- EngineBlox.VERSION_MINOR = 0;
136
+ EngineBlox.VERSION = "1.0.0";
226
137
  /**
227
- * Patch version number
138
+ * Maximum bytes retained from callee returndata on guarded execution (`EngineBlox.executeTransaction` path).
139
+ * Matches `EngineBlox.MAX_RESULT_PREVIEW_BYTES` (32 KiB).
228
140
  */
229
- EngineBlox.VERSION_PATCH = 0;
141
+ EngineBlox.MAX_RESULT_PREVIEW_BYTES = 32768n;
230
142
  // ============ FUNCTION SELECTORS ============
231
143
  /**
232
144
  * Native token transfer selector (reserved signature for simple ETH transfers)
@@ -238,14 +150,14 @@ EngineBlox.NATIVE_TRANSFER_SELECTOR = ('0x' + k256(new TextEncoder().encode("__b
238
150
  */
239
151
  EngineBlox.NATIVE_TRANSFER_OPERATION = keccak256("NATIVE_TRANSFER");
240
152
  /**
241
- * Payment update selector (reserved signature for payment detail updates)
242
- * Computed as bytes4(keccak256("__bloxchain_update_payment__()"))
153
+ * Pseudo-selector: whitelist key for attached payment recipients (native + ERC20 payout addresses).
154
+ * Matches `ATTACHED_PAYMENT_RECIPIENT_SELECTOR` in EngineBlox.sol.
243
155
  */
244
- EngineBlox.UPDATE_PAYMENT_SELECTOR = ('0x' + k256(new TextEncoder().encode("__bloxchain_update_payment__()")).slice(2, 10));
156
+ EngineBlox.ATTACHED_PAYMENT_RECIPIENT_SELECTOR = ('0x' + k256(new TextEncoder().encode('__bloxchain_attached_payment_recipient__()')).slice(2, 10));
245
157
  /**
246
- * Payment update operation type hash
158
+ * Standard IERC20 `transfer(address,uint256)` whitelist key for token contracts in attached ERC20 payments.
247
159
  */
248
- EngineBlox.UPDATE_PAYMENT_OPERATION = keccak256("UPDATE_PAYMENT");
160
+ EngineBlox.ERC20_TRANSFER_SELECTOR = ('0x' + k256(new TextEncoder().encode('transfer(address,uint256)')).slice(2, 10));
249
161
  // ============ ROLE CONSTANTS ============
250
162
  /**
251
163
  * Owner role hash
@@ -1 +1 @@
1
- {"version":3,"file":"EngineBlox.js","sourceRoot":"","sources":["../../lib/EngineBlox.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,IAAI,IAAI,EAAqC,cAAc,EAAc,MAAM,MAAM,CAAC;AAExG,OAAO,EAAgB,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AAEnE;;GAEG;AACH,MAAM,SAAS,GAAG,CAAC,GAAW,EAAO,EAAE;IACrC,OAAO,IAAI,CAAC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G;AACa,oCAAyB,GAAQ,SAAS,CAAC,iBAAiB,CAAC,CAAC;AAE9E;;;GAGG;AACa,8CAAmC,GAAQ,CACzD,IAAI,GAAG,IAAI,CAAC,IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,4CAA4C,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,CAC1F,CAAC;AAET;;GAEG;AACa,kCAAuB,GAAQ,CAC7C,IAAI,GAAG,IAAI,CAAC,IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,2BAA2B,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,CACzE,CAAC;AAET,2CAA2C;AAE3C;;GAEG;AACa,qBAAU,GAAQ,SAAS,CAAC,YAAY,CAAC,CAAC;AAE1D;;GAEG;AACa,2BAAgB,GAAQ,SAAS,CAAC,kBAAkB,CAAC,CAAC;AAEtE;;GAEG;AACa,wBAAa,GAAQ,SAAS,CAAC,eAAe,CAAC,CAAC;AA0GlE;;GAEG;AACH,eAAe,UAAU,CAAC"}
@@ -1,15 +1,42 @@
1
1
  /**
2
2
  * GuardControllerDefinitions
3
- * Pure helpers for building execution params for GuardController operations.
4
- * Mirrors GuardControllerDefinitions.sol; no contract calls.
5
- * Uses parseAbiParameters + array-of-[actionType,data] to match web3 encodeParameter('tuple(uint8,bytes)[]', [[actionType, data], ...]).
3
+ * Calls the deployed GuardControllerDefinitions contract for specs and encoding.
4
+ * Single source of truth: action names, formats, and encoding come from the contract.
5
+ * @see contracts/core/execution/lib/definitions/GuardControllerDefinitions.sol
6
+ * @see scripts/sanity/guard-controller/base-test.cjs createGuardConfigBatchMetaTx (actionsArray = [actionType, data] per element)
6
7
  */
7
- import { Hex } from 'viem';
8
+ import { type Address, type Hex, type PublicClient } from 'viem';
8
9
  import type { GuardConfigAction } from '../../types/core.execution.index';
10
+ import type { TxAction } from '../../types/lib.index';
9
11
  /**
10
12
  * Builds execution params for executeGuardConfigBatch((uint8,bytes)[]).
11
- * Equivalent to GuardControllerDefinitions.guardConfigBatchExecutionParams in Solidity.
12
- * Same encoding as web3.eth.abi.encodeParameter('tuple(uint8,bytes)[]', actionsArray).
13
+ * Encoding matches GuardControllerDefinitions.sol guardConfigBatchExecutionParams (abi.encode(actions)).
14
+ * Same format as scripts/sanity (direct contract tests); single source of truth in this module.
13
15
  */
14
- export declare function guardConfigBatchExecutionParams(actions: GuardConfigAction[]): Hex;
16
+ export declare function guardConfigBatchExecutionParams(_client: PublicClient, _definitionAddress: Address, actions: GuardConfigAction[]): Hex;
17
+ /**
18
+ * Returns all available GuardConfig action types and their ABI decode formats from the contract.
19
+ * Index i in both arrays corresponds to GuardConfigActionType enum value i.
20
+ */
21
+ export declare function getGuardConfigActionSpecs(client: PublicClient, definitionAddress: Address): Promise<{
22
+ actionNames: string[];
23
+ formats: string[];
24
+ }>;
25
+ /**
26
+ * Encodes data for ADD_TARGET_TO_WHITELIST. Matches GuardControllerDefinitions.sol encodeAddTargetToWhitelist (abi.encode(functionSelector, target)).
27
+ */
28
+ export declare function encodeAddTargetToWhitelist(_client: PublicClient, _definitionAddress: Address, functionSelector: Hex, target: Address): Hex;
29
+ /**
30
+ * Encodes data for REMOVE_TARGET_FROM_WHITELIST. Matches GuardControllerDefinitions.sol encodeRemoveTargetFromWhitelist (abi.encode(functionSelector, target)).
31
+ */
32
+ export declare function encodeRemoveTargetFromWhitelist(_client: PublicClient, _definitionAddress: Address, functionSelector: Hex, target: Address): Hex;
33
+ /**
34
+ * Encodes data for REGISTER_FUNCTION. Matches GuardControllerDefinitions.sol encodeRegisterFunction (abi.encode(functionSignature, operationName, supportedActions)).
35
+ * supportedActions: array of TxAction enum values (e.g. TxAction.EXECUTE_TIME_DELAY_REQUEST).
36
+ */
37
+ export declare function encodeRegisterFunction(_client: PublicClient, _definitionAddress: Address, functionSignature: string, operationName: string, supportedActions: TxAction[]): Hex;
38
+ /**
39
+ * Encodes data for UNREGISTER_FUNCTION. Matches GuardControllerDefinitions.sol encodeUnregisterFunction (abi.encode(functionSelector, safeRemoval)).
40
+ */
41
+ export declare function encodeUnregisterFunction(_client: PublicClient, _definitionAddress: Address, functionSelector: Hex, safeRemoval: boolean): Hex;
15
42
  //# sourceMappingURL=GuardControllerDefinitions.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"GuardControllerDefinitions.d.ts","sourceRoot":"","sources":["../../../lib/definitions/GuardControllerDefinitions.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,GAAG,EAA2C,MAAM,MAAM,CAAC;AACpE,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,kCAAkC,CAAC;AAE1E;;;;GAIG;AACH,wBAAgB,+BAA+B,CAAC,OAAO,EAAE,iBAAiB,EAAE,GAAG,GAAG,CASjF"}
1
+ {"version":3,"file":"GuardControllerDefinitions.d.ts","sourceRoot":"","sources":["../../../lib/definitions/GuardControllerDefinitions.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAY,KAAK,OAAO,EAAE,KAAK,GAAG,EAAE,KAAK,YAAY,EAAuD,MAAM,MAAM,CAAC;AAEhI,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,kCAAkC,CAAC;AAC1E,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AAWtD;;;;GAIG;AACH,wBAAgB,+BAA+B,CAC7C,OAAO,EAAE,YAAY,EACrB,kBAAkB,EAAE,OAAO,EAC3B,OAAO,EAAE,iBAAiB,EAAE,GAC3B,GAAG,CASL;AAED;;;GAGG;AACH,wBAAsB,yBAAyB,CAC7C,MAAM,EAAE,YAAY,EACpB,iBAAiB,EAAE,OAAO,GACzB,OAAO,CAAC;IAAE,WAAW,EAAE,MAAM,EAAE,CAAC;IAAC,OAAO,EAAE,MAAM,EAAE,CAAA;CAAE,CAAC,CAOvD;AAED;;GAEG;AACH,wBAAgB,0BAA0B,CACxC,OAAO,EAAE,YAAY,EACrB,kBAAkB,EAAE,OAAO,EAC3B,gBAAgB,EAAE,GAAG,EACrB,MAAM,EAAE,OAAO,GACd,GAAG,CAEL;AAED;;GAEG;AACH,wBAAgB,+BAA+B,CAC7C,OAAO,EAAE,YAAY,EACrB,kBAAkB,EAAE,OAAO,EAC3B,gBAAgB,EAAE,GAAG,EACrB,MAAM,EAAE,OAAO,GACd,GAAG,CAEL;AAED;;;GAGG;AACH,wBAAgB,sBAAsB,CACpC,OAAO,EAAE,YAAY,EACrB,kBAAkB,EAAE,OAAO,EAC3B,iBAAiB,EAAE,MAAM,EACzB,aAAa,EAAE,MAAM,EACrB,gBAAgB,EAAE,QAAQ,EAAE,GAC3B,GAAG,CAML;AAED;;GAEG;AACH,wBAAgB,wBAAwB,CACtC,OAAO,EAAE,YAAY,EACrB,kBAAkB,EAAE,OAAO,EAC3B,gBAAgB,EAAE,GAAG,EACrB,WAAW,EAAE,OAAO,GACnB,GAAG,CAEL"}
@@ -1,20 +1,72 @@
1
1
  /**
2
2
  * GuardControllerDefinitions
3
- * Pure helpers for building execution params for GuardController operations.
4
- * Mirrors GuardControllerDefinitions.sol; no contract calls.
5
- * Uses parseAbiParameters + array-of-[actionType,data] to match web3 encodeParameter('tuple(uint8,bytes)[]', [[actionType, data], ...]).
3
+ * Calls the deployed GuardControllerDefinitions contract for specs and encoding.
4
+ * Single source of truth: action names, formats, and encoding come from the contract.
5
+ * @see contracts/core/execution/lib/definitions/GuardControllerDefinitions.sol
6
+ * @see scripts/sanity/guard-controller/base-test.cjs createGuardConfigBatchMetaTx (actionsArray = [actionType, data] per element)
6
7
  */
7
- import { encodeAbiParameters, parseAbiParameters } from 'viem';
8
+ import { bytesToHex, encodeAbiParameters, parseAbiParameters } from 'viem';
9
+ import GuardControllerDefinitionsAbi from '../../abi/GuardControllerDefinitions.abi.json';
10
+ const ABI = GuardControllerDefinitionsAbi;
11
+ /** Normalize bytes to ABI Hex (0x-prefixed); empty -> '0x'. */
12
+ function normalizeData(data) {
13
+ if (data === undefined || data === null)
14
+ return '0x';
15
+ if (typeof data === 'string')
16
+ return data.startsWith('0x') ? data : `0x${data}`;
17
+ return bytesToHex(data);
18
+ }
8
19
  /**
9
20
  * Builds execution params for executeGuardConfigBatch((uint8,bytes)[]).
10
- * Equivalent to GuardControllerDefinitions.guardConfigBatchExecutionParams in Solidity.
11
- * Same encoding as web3.eth.abi.encodeParameter('tuple(uint8,bytes)[]', actionsArray).
21
+ * Encoding matches GuardControllerDefinitions.sol guardConfigBatchExecutionParams (abi.encode(actions)).
22
+ * Same format as scripts/sanity (direct contract tests); single source of truth in this module.
12
23
  */
13
- export function guardConfigBatchExecutionParams(actions) {
14
- const actionsArray = actions.map((a) => ({
24
+ export function guardConfigBatchExecutionParams(_client, _definitionAddress, actions) {
25
+ const actionsTuple = actions.map((a) => ({
15
26
  actionType: Number(a.actionType),
16
- data: a.data
27
+ data: normalizeData(a.data)
28
+ }));
29
+ return encodeAbiParameters(parseAbiParameters('(uint8 actionType, bytes data)[]'), [actionsTuple]);
30
+ }
31
+ /**
32
+ * Returns all available GuardConfig action types and their ABI decode formats from the contract.
33
+ * Index i in both arrays corresponds to GuardConfigActionType enum value i.
34
+ */
35
+ export async function getGuardConfigActionSpecs(client, definitionAddress) {
36
+ const result = (await client.readContract({
37
+ address: definitionAddress,
38
+ abi: ABI,
39
+ functionName: 'getGuardConfigActionSpecs'
17
40
  }));
18
- return encodeAbiParameters(parseAbiParameters('(uint8 actionType, bytes data)[]'), [actionsArray]);
41
+ return { actionNames: result[0], formats: result[1] };
42
+ }
43
+ /**
44
+ * Encodes data for ADD_TARGET_TO_WHITELIST. Matches GuardControllerDefinitions.sol encodeAddTargetToWhitelist (abi.encode(functionSelector, target)).
45
+ */
46
+ export function encodeAddTargetToWhitelist(_client, _definitionAddress, functionSelector, target) {
47
+ return encodeAbiParameters(parseAbiParameters('bytes4, address'), [functionSelector, target]);
48
+ }
49
+ /**
50
+ * Encodes data for REMOVE_TARGET_FROM_WHITELIST. Matches GuardControllerDefinitions.sol encodeRemoveTargetFromWhitelist (abi.encode(functionSelector, target)).
51
+ */
52
+ export function encodeRemoveTargetFromWhitelist(_client, _definitionAddress, functionSelector, target) {
53
+ return encodeAbiParameters(parseAbiParameters('bytes4, address'), [functionSelector, target]);
54
+ }
55
+ /**
56
+ * Encodes data for REGISTER_FUNCTION. Matches GuardControllerDefinitions.sol encodeRegisterFunction (abi.encode(functionSignature, operationName, supportedActions)).
57
+ * supportedActions: array of TxAction enum values (e.g. TxAction.EXECUTE_TIME_DELAY_REQUEST).
58
+ */
59
+ export function encodeRegisterFunction(_client, _definitionAddress, functionSignature, operationName, supportedActions) {
60
+ return encodeAbiParameters(parseAbiParameters('string, string, uint8[]'), [
61
+ functionSignature,
62
+ operationName,
63
+ supportedActions.map((a) => Number(a))
64
+ ]);
65
+ }
66
+ /**
67
+ * Encodes data for UNREGISTER_FUNCTION. Matches GuardControllerDefinitions.sol encodeUnregisterFunction (abi.encode(functionSelector, safeRemoval)).
68
+ */
69
+ export function encodeUnregisterFunction(_client, _definitionAddress, functionSelector, safeRemoval) {
70
+ return encodeAbiParameters(parseAbiParameters('bytes4, bool'), [functionSelector, safeRemoval]);
19
71
  }
20
72
  //# sourceMappingURL=GuardControllerDefinitions.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"GuardControllerDefinitions.js","sourceRoot":"","sources":["../../../lib/definitions/GuardControllerDefinitions.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAO,mBAAmB,EAAE,kBAAkB,EAAE,MAAM,MAAM,CAAC;AAGpE;;;;GAIG;AACH,MAAM,UAAU,+BAA+B,CAAC,OAA4B;IAC1E,MAAM,YAAY,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;QACvC,UAAU,EAAE,MAAM,CAAC,CAAC,CAAC,UAAU,CAAC;QAChC,IAAI,EAAE,CAAC,CAAC,IAAI;KACb,CAAC,CAAC,CAAC;IACJ,OAAO,mBAAmB,CACxB,kBAAkB,CAAC,kCAAkC,CAAC,EACtD,CAAC,YAAY,CAAC,CACR,CAAC;AACX,CAAC"}
1
+ {"version":3,"file":"GuardControllerDefinitions.js","sourceRoot":"","sources":["../../../lib/definitions/GuardControllerDefinitions.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAuD,UAAU,EAAE,mBAAmB,EAAE,kBAAkB,EAAE,MAAM,MAAM,CAAC;AAChI,OAAO,6BAA6B,MAAM,+CAA+C,CAAC;AAI1F,MAAM,GAAG,GAAG,6BAAoC,CAAC;AAEjD,+DAA+D;AAC/D,SAAS,aAAa,CAAC,IAAyC;IAC9D,IAAI,IAAI,KAAK,SAAS,IAAI,IAAI,KAAK,IAAI;QAAE,OAAO,IAAI,CAAC;IACrD,IAAI,OAAO,IAAI,KAAK,QAAQ;QAAE,OAAO,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC,CAAE,IAAY,CAAC,CAAC,CAAE,KAAK,IAAI,EAAU,CAAC;IAClG,OAAO,UAAU,CAAC,IAAkB,CAAQ,CAAC;AAC/C,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,+BAA+B,CAC7C,OAAqB,EACrB,kBAA2B,EAC3B,OAA4B;IAE5B,MAAM,YAAY,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;QACvC,UAAU,EAAE,MAAM,CAAC,CAAC,CAAC,UAAU,CAAC;QAChC,IAAI,EAAE,aAAa,CAAC,CAAC,CAAC,IAAI,CAAC;KAC5B,CAAC,CAAC,CAAC;IACJ,OAAO,mBAAmB,CACxB,kBAAkB,CAAC,kCAAkC,CAAC,EACtD,CAAC,YAAY,CAAC,CACR,CAAC;AACX,CAAC;AAED;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,yBAAyB,CAC7C,MAAoB,EACpB,iBAA0B;IAE1B,MAAM,MAAM,GAAG,CAAC,MAAM,MAAM,CAAC,YAAY,CAAC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Definitions
3
- * Pure helpers for building execution params for RuntimeRBAC operations.
4
- * Mirrors RuntimeRBACDefinitions.sol; no contract calls.
5
- * Uses parseAbiParameters + array-of-[actionType,data] to match web3 encodeParameter('tuple(uint8,bytes)[]', ...).
3
+ * Calls the deployed RuntimeRBACDefinitions contract for specs and encoding.
4
+ * Single source of truth: action names, formats, and encoding come from the contract.
5
+ * @see contracts/core/access/lib/definitions/RuntimeRBACDefinitions.sol
6
6
  */
7
- import { Hex } from 'viem';
7
+ import { type Address, type Hex, type PublicClient } from 'viem';
8
8
  import type { RoleConfigAction } from '../../types/core.access.index';
9
+ /**
10
+ * FunctionPermission shape for encodeAddFunctionToRole.
11
+ * Matches Solidity EngineBlox.FunctionPermission (functionSelector, grantedActionsBitmap, handlerForSelectors).
12
+ */
13
+ export interface FunctionPermissionForEncoding {
14
+ functionSelector: Hex;
15
+ grantedActionsBitmap: number;
16
+ handlerForSelectors: readonly Hex[];
17
+ }
9
18
  /**
10
19
  * Builds execution params for executeRoleConfigBatch((uint8,bytes)[]).
11
- * Equivalent to RuntimeRBACDefinitions.roleConfigBatchExecutionParams in Solidity.
12
- * Same encoding as web3.eth.abi.encodeParameter('tuple(uint8,bytes)[]', actionsArray).
20
+ * Encoding matches RuntimeRBACDefinitions.sol roleConfigBatchExecutionParams (abi.encode(actions)).
21
+ * Same format as scripts/sanity (direct contract tests); single source of truth in this module.
22
+ */
23
+ export declare function roleConfigBatchExecutionParams(_client: PublicClient, _definitionAddress: Address, actions: RoleConfigAction[]): Hex;
24
+ /**
25
+ * Returns all available RoleConfig action types and their ABI decode formats from the contract.
26
+ * Index i in both arrays corresponds to RoleConfigActionType enum value i.
27
+ */
28
+ export declare function getRoleConfigActionSpecs(client: PublicClient, definitionAddress: Address): Promise<{
29
+ actionNames: string[];
30
+ formats: string[];
31
+ }>;
32
+ /**
33
+ * Encodes data for CREATE_ROLE. Matches RuntimeRBACDefinitions.sol encodeCreateRole (abi.encode(roleName, maxWallets)).
34
+ */
35
+ export declare function encodeCreateRole(_client: PublicClient, _definitionAddress: Address, roleName: string, maxWallets: bigint): Hex;
36
+ /**
37
+ * Encodes data for REMOVE_ROLE. Matches RuntimeRBACDefinitions.sol encodeRemoveRole (abi.encode(roleHash)).
38
+ */
39
+ export declare function encodeRemoveRole(_client: PublicClient, _definitionAddress: Address, roleHash: Hex): Hex;
40
+ /**
41
+ * Encodes data for ADD_WALLET. Matches RuntimeRBACDefinitions.sol encodeAddWallet (abi.encode(roleHash, wallet)).
42
+ */
43
+ export declare function encodeAddWallet(_client: PublicClient, _definitionAddress: Address, roleHash: Hex, wallet: Address): Hex;
44
+ /**
45
+ * Encodes data for REVOKE_WALLET. Matches RuntimeRBACDefinitions.sol encodeRevokeWallet (abi.encode(roleHash, wallet)).
46
+ */
47
+ export declare function encodeRevokeWallet(_client: PublicClient, _definitionAddress: Address, roleHash: Hex, wallet: Address): Hex;
48
+ /**
49
+ * Encodes data for ADD_FUNCTION_TO_ROLE. Matches RuntimeRBACDefinitions.sol encodeAddFunctionToRole (abi.encode(roleHash, functionPermission)).
50
+ */
51
+ export declare function encodeAddFunctionToRole(_client: PublicClient, _definitionAddress: Address, roleHash: Hex, functionPermission: FunctionPermissionForEncoding): Hex;
52
+ /**
53
+ * Encodes data for REMOVE_FUNCTION_FROM_ROLE. Matches RuntimeRBACDefinitions.sol encodeRemoveFunctionFromRole (abi.encode(roleHash, functionSelector)).
13
54
  */
14
- export declare function roleConfigBatchExecutionParams(actions: RoleConfigAction[]): Hex;
55
+ export declare function encodeRemoveFunctionFromRole(_client: PublicClient, _definitionAddress: Address, roleHash: Hex, functionSelector: Hex): Hex;
15
56
  //# sourceMappingURL=RuntimeRBACDefinitions.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"RuntimeRBACDefinitions.d.ts","sourceRoot":"","sources":["../../../lib/definitions/RuntimeRBACDefinitions.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,GAAG,EAA2C,MAAM,MAAM,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eAAe,CAC7B,OAAO,EAAE,YAAY,EACrB,kBAAkB,EAAE,OAAO,EAC3B,QAAQ,EAAE,GAAG,EACb,MAAM,EAAE,OAAO,GACd,GAAG,CAEL;AAED;;GAEG;AACH,wBAAgB,kBAAkB,CAChC,OAAO,EAAE,YAAY,EACrB,kBAAkB,EAAE,OAAO,EAC3B,QAAQ,EAAE,GAAG,EACb,MAAM,EAAE,OAAO,GACd,GAAG,CAEL;AAED;;GAEG;AACH,wBAAgB,uBAAuB,CACrC,OAAO,EAAE,YAAY,EACrB,kBAAkB,EAAE,OAAO,EAC3B,QAAQ,EAAE,GAAG,EACb,kBAAkB,EAAE,6BAA6B,GAChD,GAAG,CAUL;AAED;;GAEG;AACH,wBAAgB,4BAA4B,CAC1C,OAAO,EAAE,YAAY,EACrB,kBAAkB,EAAE,OAAO,EAC3B,QAAQ,EAAE,GAAG,EACb,gBAAgB,EAAE,GAAG,GACpB,GAAG,CAEL"}
@@ -1,20 +1,83 @@
1
1
  /**
2
2
  * RuntimeRBACDefinitions
3
- * Pure helpers for building execution params for RuntimeRBAC operations.
4
- * Mirrors RuntimeRBACDefinitions.sol; no contract calls.
5
- * Uses parseAbiParameters + array-of-[actionType,data] to match web3 encodeParameter('tuple(uint8,bytes)[]', ...).
3
+ * Calls the deployed RuntimeRBACDefinitions contract for specs and encoding.
4
+ * Single source of truth: action names, formats, and encoding come from the contract.
5
+ * @see contracts/core/access/lib/definitions/RuntimeRBACDefinitions.sol
6
6
  */
7
- import { encodeAbiParameters, parseAbiParameters } from 'viem';
7
+ import { bytesToHex, encodeAbiParameters, parseAbiParameters } from 'viem';
8
+ import RuntimeRBACDefinitionsAbi from '../../abi/RuntimeRBACDefinitions.abi.json';
9
+ const ABI = RuntimeRBACDefinitionsAbi;
10
+ /** Normalize bytes to ABI Hex (0x-prefixed); empty -> '0x'. */
11
+ function normalizeData(data) {
12
+ if (data === undefined || data === null)
13
+ return '0x';
14
+ if (typeof data === 'string')
15
+ return data.startsWith('0x') ? data : `0x${data}`;
16
+ return bytesToHex(data);
17
+ }
8
18
  /**
9
19
  * Builds execution params for executeRoleConfigBatch((uint8,bytes)[]).
10
- * Equivalent to RuntimeRBACDefinitions.roleConfigBatchExecutionParams in Solidity.
11
- * Same encoding as web3.eth.abi.encodeParameter('tuple(uint8,bytes)[]', actionsArray).
20
+ * Encoding matches RuntimeRBACDefinitions.sol roleConfigBatchExecutionParams (abi.encode(actions)).
21
+ * Same format as scripts/sanity (direct contract tests); single source of truth in this module.
12
22
  */
13
- export function roleConfigBatchExecutionParams(actions) {
14
- const actionsArray = actions.map((a) => ({
23
+ export function roleConfigBatchExecutionParams(_client, _definitionAddress, actions) {
24
+ const actionsTuple = actions.map((a) => ({
15
25
  actionType: Number(a.actionType),
16
- data: a.data
26
+ data: normalizeData(a.data)
27
+ }));
28
+ return encodeAbiParameters(parseAbiParameters('(uint8 actionType, bytes data)[]'), [actionsTuple]);
29
+ }
30
+ /**
31
+ * Returns all available RoleConfig action types and their ABI decode formats from the contract.
32
+ * Index i in both arrays corresponds to RoleConfigActionType enum value i.
33
+ */
34
+ export async function getRoleConfigActionSpecs(client, definitionAddress) {
35
+ const result = (await client.readContract({
36
+ address: definitionAddress,
37
+ abi: ABI,
38
+ functionName: 'getRoleConfigActionSpecs'
17
39
  }));
18
- return encodeAbiParameters(parseAbiParameters('(uint8 actionType, bytes data)[]'), [actionsArray]);
40
+ return { actionNames: result[0], formats: result[1] };
41
+ }
42
+ /**
43
+ * Encodes data for CREATE_ROLE. Matches RuntimeRBACDefinitions.sol encodeCreateRole (abi.encode(roleName, maxWallets)).
44
+ */
45
+ export function encodeCreateRole(_client, _definitionAddress, roleName, maxWallets) {
46
+ return encodeAbiParameters(parseAbiParameters('string, uint256'), [roleName, maxWallets]);
47
+ }
48
+ /**
49
+ * Encodes data for REMOVE_ROLE. Matches RuntimeRBACDefinitions.sol encodeRemoveRole (abi.encode(roleHash)).
50
+ */
51
+ export function encodeRemoveRole(_client, _definitionAddress, roleHash) {
52
+ return encodeAbiParameters(parseAbiParameters('bytes32'), [roleHash]);
53
+ }
54
+ /**
55
+ * Encodes data for ADD_WALLET. Matches RuntimeRBACDefinitions.sol encodeAddWallet (abi.encode(roleHash, wallet)).
56
+ */
57
+ export function encodeAddWallet(_client, _definitionAddress, roleHash, wallet) {
58
+ return encodeAbiParameters(parseAbiParameters('bytes32, address'), [roleHash, wallet]);
59
+ }
60
+ /**
61
+ * Encodes data for REVOKE_WALLET. Matches RuntimeRBACDefinitions.sol encodeRevokeWallet (abi.encode(roleHash, wallet)).
62
+ */
63
+ export function encodeRevokeWallet(_client, _definitionAddress, roleHash, wallet) {
64
+ return encodeAbiParameters(parseAbiParameters('bytes32, address'), [roleHash, wallet]);
65
+ }
66
+ /**
67
+ * Encodes data for ADD_FUNCTION_TO_ROLE. Matches RuntimeRBACDefinitions.sol encodeAddFunctionToRole (abi.encode(roleHash, functionPermission)).
68
+ */
69
+ export function encodeAddFunctionToRole(_client, _definitionAddress, roleHash, functionPermission) {
70
+ const tuple = [
71
+ functionPermission.functionSelector,
72
+ functionPermission.grantedActionsBitmap,
73
+ [...functionPermission.handlerForSelectors]
74
+ ];
75
+ return encodeAbiParameters(parseAbiParameters('bytes32, (bytes4, uint16, bytes4[])'), [roleHash, tuple]);
76
+ }
77
+ /**
78
+ * Encodes data for REMOVE_FUNCTION_FROM_ROLE. Matches RuntimeRBACDefinitions.sol encodeRemoveFunctionFromRole (abi.encode(roleHash, functionSelector)).
79
+ */
80
+ export function encodeRemoveFunctionFromRole(_client, _definitionAddress, roleHash, functionSelector) {
81
+ return encodeAbiParameters(parseAbiParameters('bytes32, bytes4'), [roleHash, functionSelector]);
19
82
  }
20
83
  //# sourceMappingURL=RuntimeRBACDefinitions.js.map