@bloxchain/sdk 1.0.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/README.md +338 -0
- package/abi/BareBlox.abi.json +1341 -0
- package/abi/BaseStateMachine.abi.json +1308 -0
- package/abi/ControlBlox.abi.json +6210 -0
- package/abi/EngineBlox.abi.json +872 -0
- package/abi/GuardController.abi.json +3045 -0
- package/abi/IDefinition.abi.json +94 -0
- package/abi/RoleBlox.abi.json +4569 -0
- package/abi/RuntimeRBAC.abi.json +1857 -0
- package/abi/RuntimeRBACDefinitions.abi.json +133 -0
- package/abi/SecureBlox.abi.json +4085 -0
- package/abi/SecureOwnable.abi.json +4085 -0
- package/abi/SecureOwnableDefinitions.abi.json +354 -0
- package/abi/SimpleRWA20.abi.json +5545 -0
- package/abi/SimpleRWA20Definitions.abi.json +172 -0
- package/abi/SimpleVault.abi.json +5208 -0
- package/abi/SimpleVaultDefinitions.abi.json +250 -0
- package/dist/abi/BaseStateMachine.abi.json +1308 -0
- package/dist/abi/GuardController.abi.json +3045 -0
- package/dist/abi/IDefinition.abi.json +94 -0
- package/dist/abi/RuntimeRBAC.abi.json +1857 -0
- package/dist/abi/SecureOwnable.abi.json +4085 -0
- package/dist/contracts/BaseStateMachine.d.ts +83 -0
- package/dist/contracts/BaseStateMachine.d.ts.map +1 -0
- package/dist/contracts/BaseStateMachine.js +251 -0
- package/dist/contracts/BaseStateMachine.js.map +1 -0
- package/dist/contracts/GuardController.d.ts +120 -0
- package/dist/contracts/GuardController.d.ts.map +1 -0
- package/dist/contracts/GuardController.js +149 -0
- package/dist/contracts/GuardController.js.map +1 -0
- package/dist/contracts/RuntimeRBAC.d.ts +56 -0
- package/dist/contracts/RuntimeRBAC.d.ts.map +1 -0
- package/dist/contracts/RuntimeRBAC.js +57 -0
- package/dist/contracts/RuntimeRBAC.js.map +1 -0
- package/dist/contracts/SecureOwnable.d.ts +41 -0
- package/dist/contracts/SecureOwnable.d.ts.map +1 -0
- package/dist/contracts/SecureOwnable.js +82 -0
- package/dist/contracts/SecureOwnable.js.map +1 -0
- package/dist/index.d.ts +30 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +32 -0
- package/dist/index.js.map +1 -0
- package/dist/interfaces/base.index.d.ts +18 -0
- package/dist/interfaces/base.index.d.ts.map +1 -0
- package/dist/interfaces/base.index.js +2 -0
- package/dist/interfaces/base.index.js.map +1 -0
- package/dist/interfaces/base.state.machine.index.d.ts +72 -0
- package/dist/interfaces/base.state.machine.index.d.ts.map +1 -0
- package/dist/interfaces/base.state.machine.index.js +2 -0
- package/dist/interfaces/base.state.machine.index.js.map +1 -0
- package/dist/interfaces/core.access.index.d.ts +37 -0
- package/dist/interfaces/core.access.index.d.ts.map +1 -0
- package/dist/interfaces/core.access.index.js +2 -0
- package/dist/interfaces/core.access.index.js.map +1 -0
- package/dist/interfaces/core.execution.index.d.ts +44 -0
- package/dist/interfaces/core.execution.index.d.ts.map +1 -0
- package/dist/interfaces/core.execution.index.js +2 -0
- package/dist/interfaces/core.execution.index.js.map +1 -0
- package/dist/interfaces/core.security.index.d.ts +83 -0
- package/dist/interfaces/core.security.index.d.ts.map +1 -0
- package/dist/interfaces/core.security.index.js +2 -0
- package/dist/interfaces/core.security.index.js.map +1 -0
- package/dist/interfaces/definition.index.d.ts +38 -0
- package/dist/interfaces/definition.index.d.ts.map +1 -0
- package/dist/interfaces/definition.index.js +2 -0
- package/dist/interfaces/definition.index.js.map +1 -0
- package/dist/interfaces/lib.index.d.ts +83 -0
- package/dist/interfaces/lib.index.d.ts.map +1 -0
- package/dist/interfaces/lib.index.js +2 -0
- package/dist/interfaces/lib.index.js.map +1 -0
- package/dist/lib/Definition.d.ts +84 -0
- package/dist/lib/Definition.d.ts.map +1 -0
- package/dist/lib/Definition.js +159 -0
- package/dist/lib/Definition.js.map +1 -0
- package/dist/lib/EngineBlox.d.ts +167 -0
- package/dist/lib/EngineBlox.d.ts.map +1 -0
- package/dist/lib/EngineBlox.js +266 -0
- package/dist/lib/EngineBlox.js.map +1 -0
- package/dist/types/base.state.machine.index.d.ts +45 -0
- package/dist/types/base.state.machine.index.d.ts.map +1 -0
- package/dist/types/base.state.machine.index.js +49 -0
- package/dist/types/base.state.machine.index.js.map +1 -0
- package/dist/types/core.access.index.d.ts +51 -0
- package/dist/types/core.access.index.d.ts.map +1 -0
- package/dist/types/core.access.index.js +41 -0
- package/dist/types/core.access.index.js.map +1 -0
- package/dist/types/core.execution.index.d.ts +36 -0
- package/dist/types/core.execution.index.d.ts.map +1 -0
- package/dist/types/core.execution.index.js +30 -0
- package/dist/types/core.execution.index.js.map +1 -0
- package/dist/types/core.security.index.d.ts +36 -0
- package/dist/types/core.security.index.d.ts.map +1 -0
- package/dist/types/core.security.index.js +37 -0
- package/dist/types/core.security.index.js.map +1 -0
- package/dist/types/definition.index.d.ts +36 -0
- package/dist/types/definition.index.d.ts.map +1 -0
- package/dist/types/definition.index.js +4 -0
- package/dist/types/definition.index.js.map +1 -0
- package/dist/types/lib.index.d.ts +66 -0
- package/dist/types/lib.index.d.ts.map +1 -0
- package/dist/types/lib.index.js +68 -0
- package/dist/types/lib.index.js.map +1 -0
- package/dist/utils/bitmap.d.ts +75 -0
- package/dist/utils/bitmap.d.ts.map +1 -0
- package/dist/utils/bitmap.js +124 -0
- package/dist/utils/bitmap.js.map +1 -0
- package/dist/utils/contract-errors.d.ts +536 -0
- package/dist/utils/contract-errors.d.ts.map +1 -0
- package/dist/utils/contract-errors.js +412 -0
- package/dist/utils/contract-errors.js.map +1 -0
- package/dist/utils/erc20/ERC20Token.abi.json +217 -0
- package/dist/utils/erc20/erc20Token.d.ts +83 -0
- package/dist/utils/erc20/erc20Token.d.ts.map +1 -0
- package/dist/utils/erc20/erc20Token.js +173 -0
- package/dist/utils/erc20/erc20Token.js.map +1 -0
- package/dist/utils/interface-ids.d.ts +59 -0
- package/dist/utils/interface-ids.d.ts.map +1 -0
- package/dist/utils/interface-ids.js +149 -0
- package/dist/utils/interface-ids.js.map +1 -0
- package/dist/utils/metaTx/metaTransaction.d.ts +138 -0
- package/dist/utils/metaTx/metaTransaction.d.ts.map +1 -0
- package/dist/utils/metaTx/metaTransaction.js +271 -0
- package/dist/utils/metaTx/metaTransaction.js.map +1 -0
- package/dist/utils/validations.d.ts +104 -0
- package/dist/utils/validations.d.ts.map +1 -0
- package/dist/utils/validations.js +254 -0
- package/dist/utils/validations.js.map +1 -0
- package/dist/utils/viem-error-handler.d.ts +48 -0
- package/dist/utils/viem-error-handler.d.ts.map +1 -0
- package/dist/utils/viem-error-handler.js +172 -0
- package/dist/utils/viem-error-handler.js.map +1 -0
- package/package.json +65 -0
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { keccak256 } from 'viem';
|
|
2
|
+
/**
|
|
3
|
+
* Constants for SecureOwnable operations
|
|
4
|
+
* These match the keccak256 hashes defined in SecureOwnableDefinitions.sol
|
|
5
|
+
*/
|
|
6
|
+
export const OPERATION_TYPES = {
|
|
7
|
+
OWNERSHIP_TRANSFER: keccak256(new TextEncoder().encode("OWNERSHIP_TRANSFER")),
|
|
8
|
+
BROADCASTER_UPDATE: keccak256(new TextEncoder().encode("BROADCASTER_UPDATE")),
|
|
9
|
+
RECOVERY_UPDATE: keccak256(new TextEncoder().encode("RECOVERY_UPDATE")),
|
|
10
|
+
TIMELOCK_UPDATE: keccak256(new TextEncoder().encode("TIMELOCK_UPDATE"))
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* Constants for function selectors
|
|
14
|
+
* These match the selectors from SecureOwnableDefinitions.sol
|
|
15
|
+
*/
|
|
16
|
+
export const FUNCTION_SELECTORS = {
|
|
17
|
+
// Execution selectors
|
|
18
|
+
TRANSFER_OWNERSHIP_SELECTOR: keccak256(new TextEncoder().encode("executeTransferOwnership(address)")).slice(0, 10),
|
|
19
|
+
UPDATE_BROADCASTER_SELECTOR: keccak256(new TextEncoder().encode("executeBroadcasterUpdate(address)")).slice(0, 10),
|
|
20
|
+
UPDATE_RECOVERY_SELECTOR: keccak256(new TextEncoder().encode("executeRecoveryUpdate(address)")).slice(0, 10),
|
|
21
|
+
UPDATE_TIMELOCK_SELECTOR: keccak256(new TextEncoder().encode("executeTimeLockUpdate(uint256)")).slice(0, 10),
|
|
22
|
+
// Time delay selectors
|
|
23
|
+
TRANSFER_OWNERSHIP_REQUEST_SELECTOR: keccak256(new TextEncoder().encode("transferOwnershipRequest()")).slice(0, 10),
|
|
24
|
+
TRANSFER_OWNERSHIP_DELAYED_APPROVAL_SELECTOR: keccak256(new TextEncoder().encode("transferOwnershipDelayedApproval(uint256)")).slice(0, 10),
|
|
25
|
+
TRANSFER_OWNERSHIP_CANCELLATION_SELECTOR: keccak256(new TextEncoder().encode("transferOwnershipCancellation(uint256)")).slice(0, 10),
|
|
26
|
+
UPDATE_BROADCASTER_REQUEST_SELECTOR: keccak256(new TextEncoder().encode("updateBroadcasterRequest(address)")).slice(0, 10),
|
|
27
|
+
UPDATE_BROADCASTER_DELAYED_APPROVAL_SELECTOR: keccak256(new TextEncoder().encode("updateBroadcasterDelayedApproval(uint256)")).slice(0, 10),
|
|
28
|
+
UPDATE_BROADCASTER_CANCELLATION_SELECTOR: keccak256(new TextEncoder().encode("updateBroadcasterCancellation(uint256)")).slice(0, 10),
|
|
29
|
+
// Meta-transaction selectors
|
|
30
|
+
TRANSFER_OWNERSHIP_APPROVE_META_SELECTOR: keccak256(new TextEncoder().encode("transferOwnershipApprovalWithMetaTx(((uint256,uint256,uint8,(address,address,uint256,uint256,bytes32,bytes4,bytes),bytes32,bytes,(address,uint256,address,uint256)),(uint256,uint256,address,bytes4,uint8,uint256,uint256,address),bytes32,bytes,bytes))")).slice(0, 10),
|
|
31
|
+
TRANSFER_OWNERSHIP_CANCEL_META_SELECTOR: keccak256(new TextEncoder().encode("transferOwnershipCancellationWithMetaTx(((uint256,uint256,uint8,(address,address,uint256,uint256,bytes32,bytes4,bytes),bytes32,bytes,(address,uint256,address,uint256)),(uint256,uint256,address,bytes4,uint8,uint256,uint256,address),bytes32,bytes,bytes))")).slice(0, 10),
|
|
32
|
+
UPDATE_BROADCASTER_APPROVE_META_SELECTOR: keccak256(new TextEncoder().encode("updateBroadcasterApprovalWithMetaTx(((uint256,uint256,uint8,(address,address,uint256,uint256,bytes32,bytes4,bytes),bytes32,bytes,(address,uint256,address,uint256)),(uint256,uint256,address,bytes4,uint8,uint256,uint256,address),bytes32,bytes,bytes))")).slice(0, 10),
|
|
33
|
+
UPDATE_BROADCASTER_CANCEL_META_SELECTOR: keccak256(new TextEncoder().encode("updateBroadcasterCancellationWithMetaTx(((uint256,uint256,uint8,(address,address,uint256,uint256,bytes32,bytes4,bytes),bytes32,bytes,(address,uint256,address,uint256)),(uint256,uint256,address,bytes4,uint8,uint256,uint256,address),bytes32,bytes,bytes))")).slice(0, 10),
|
|
34
|
+
UPDATE_RECOVERY_META_SELECTOR: keccak256(new TextEncoder().encode("updateRecoveryRequestAndApprove(((uint256,uint256,uint8,(address,address,uint256,uint256,bytes32,bytes4,bytes),bytes32,bytes,(address,uint256,address,uint256)),(uint256,uint256,address,bytes4,uint8,uint256,uint256,address),bytes32,bytes,bytes))")).slice(0, 10),
|
|
35
|
+
UPDATE_TIMELOCK_META_SELECTOR: keccak256(new TextEncoder().encode("updateTimeLockRequestAndApprove(((uint256,uint256,uint8,(address,address,uint256,uint256,bytes32,bytes4,bytes),bytes32,bytes,(address,uint256,address,uint256)),(uint256,uint256,address,bytes4,uint8,uint256,uint256,address),bytes32,bytes,bytes))")).slice(0, 10)
|
|
36
|
+
};
|
|
37
|
+
//# sourceMappingURL=core.security.index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"core.security.index.js","sourceRoot":"","sources":["../../types/core.security.index.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAO,MAAM,MAAM,CAAC;AAGtC;;;GAGG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG;IAC7B,kBAAkB,EA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AAS,CAAC,IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,sPAAsP,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAQ;CACtU,CAAC"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { Hex } from 'viem';
|
|
2
|
+
import { Uint16Bitmap } from '../utils/bitmap';
|
|
3
|
+
/**
|
|
4
|
+
* TypeScript types for IDefinition interface
|
|
5
|
+
* These types correspond to the Solidity structs in IDefinition.sol
|
|
6
|
+
*
|
|
7
|
+
* Note: Workflow-related types have been moved to workflow.index.tsx
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* Function permission structure matching EngineBlox.FunctionPermission
|
|
11
|
+
*/
|
|
12
|
+
export interface FunctionPermission {
|
|
13
|
+
functionSelector: Hex;
|
|
14
|
+
grantedActionsBitmap: Uint16Bitmap;
|
|
15
|
+
handlerForSelectors: Hex[];
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Function schema structure matching EngineBlox.FunctionSchema
|
|
19
|
+
*/
|
|
20
|
+
export interface FunctionSchema {
|
|
21
|
+
functionSignature: string;
|
|
22
|
+
functionSelector: Hex;
|
|
23
|
+
operationType: Hex;
|
|
24
|
+
operationName: string;
|
|
25
|
+
supportedActionsBitmap: Uint16Bitmap;
|
|
26
|
+
isProtected: boolean;
|
|
27
|
+
handlerForSelectors: Hex[];
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Role permission structure containing role hashes and their function permissions
|
|
31
|
+
*/
|
|
32
|
+
export interface RolePermission {
|
|
33
|
+
roleHashes: Hex[];
|
|
34
|
+
functionPermissions: FunctionPermission[];
|
|
35
|
+
}
|
|
36
|
+
//# sourceMappingURL=definition.index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"definition.index.d.ts","sourceRoot":"","sources":["../../types/definition.index.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,MAAM,CAAC;AAC3B,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAG/C;;;;;GAKG;AAEH;;GAEG;AACH,MAAM,WAAW,kBAAkB;IACjC,gBAAgB,EAAE,GAAG,CAAC;IACtB,oBAAoB,EAAE,YAAY,CAAC;IACnC,mBAAmB,EAAE,GAAG,EAAE,CAAC;CAC5B;AAED;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B,iBAAiB,EAAE,MAAM,CAAC;IAC1B,gBAAgB,EAAE,GAAG,CAAC;IACtB,aAAa,EAAE,GAAG,CAAC;IACnB,aAAa,EAAE,MAAM,CAAC;IACtB,sBAAsB,EAAE,YAAY,CAAC;IACrC,WAAW,EAAE,OAAO,CAAC;IACrB,mBAAmB,EAAE,GAAG,EAAE,CAAC;CAC5B;AAED;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B,UAAU,EAAE,GAAG,EAAE,CAAC;IAClB,mBAAmB,EAAE,kBAAkB,EAAE,CAAC;CAC3C"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"definition.index.js","sourceRoot":"","sources":["../../types/definition.index.tsx"],"names":[],"mappings":";AAyCA,mEAAmE;AACnE,wFAAwF"}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Enums and constants for EngineBlox
|
|
3
|
+
*/
|
|
4
|
+
export declare const TxStatus: {
|
|
5
|
+
readonly UNDEFINED: 0;
|
|
6
|
+
readonly PENDING: 1;
|
|
7
|
+
readonly EXECUTING: 2;
|
|
8
|
+
readonly PROCESSING_PAYMENT: 3;
|
|
9
|
+
readonly CANCELLED: 4;
|
|
10
|
+
readonly COMPLETED: 5;
|
|
11
|
+
readonly FAILED: 6;
|
|
12
|
+
readonly REJECTED: 7;
|
|
13
|
+
};
|
|
14
|
+
export type TxStatus = typeof TxStatus[keyof typeof TxStatus];
|
|
15
|
+
export declare const TxAction: {
|
|
16
|
+
readonly EXECUTE_TIME_DELAY_REQUEST: 0;
|
|
17
|
+
readonly EXECUTE_TIME_DELAY_APPROVE: 1;
|
|
18
|
+
readonly EXECUTE_TIME_DELAY_CANCEL: 2;
|
|
19
|
+
readonly SIGN_META_REQUEST_AND_APPROVE: 3;
|
|
20
|
+
readonly SIGN_META_APPROVE: 4;
|
|
21
|
+
readonly SIGN_META_CANCEL: 5;
|
|
22
|
+
readonly EXECUTE_META_REQUEST_AND_APPROVE: 6;
|
|
23
|
+
readonly EXECUTE_META_APPROVE: 7;
|
|
24
|
+
readonly EXECUTE_META_CANCEL: 8;
|
|
25
|
+
};
|
|
26
|
+
export type TxAction = typeof TxAction[keyof typeof TxAction];
|
|
27
|
+
/**
|
|
28
|
+
* Constants for function selectors
|
|
29
|
+
*/
|
|
30
|
+
export declare const FUNCTION_SELECTORS: {
|
|
31
|
+
readonly TX_REQUEST: string;
|
|
32
|
+
readonly TX_DELAYED_APPROVAL: string;
|
|
33
|
+
readonly TX_CANCELLATION: string;
|
|
34
|
+
readonly META_TX_APPROVAL: string;
|
|
35
|
+
readonly META_TX_CANCELLATION: string;
|
|
36
|
+
readonly META_TX_REQUEST_AND_APPROVE: string;
|
|
37
|
+
};
|
|
38
|
+
export type FunctionSelector = typeof FUNCTION_SELECTORS[keyof typeof FUNCTION_SELECTORS];
|
|
39
|
+
/**
|
|
40
|
+
* Constants for roles
|
|
41
|
+
*/
|
|
42
|
+
export declare const ROLES: {
|
|
43
|
+
readonly OWNER_ROLE: string;
|
|
44
|
+
readonly BROADCASTER_ROLE: string;
|
|
45
|
+
readonly RECOVERY_ROLE: string;
|
|
46
|
+
};
|
|
47
|
+
export type Role = typeof ROLES[keyof typeof ROLES];
|
|
48
|
+
/**
|
|
49
|
+
* Constants for EIP-712 type hashes
|
|
50
|
+
*/
|
|
51
|
+
export declare const TYPE_HASHES: {
|
|
52
|
+
readonly DOMAIN_SEPARATOR: string;
|
|
53
|
+
readonly META_TRANSACTION: string;
|
|
54
|
+
};
|
|
55
|
+
export type TypeHash = typeof TYPE_HASHES[keyof typeof TYPE_HASHES];
|
|
56
|
+
/**
|
|
57
|
+
* Event names
|
|
58
|
+
*/
|
|
59
|
+
export declare const EVENTS: {
|
|
60
|
+
readonly REQUESTED_TX: "RequestedTx";
|
|
61
|
+
readonly TX_APPROVED: "TxApproved";
|
|
62
|
+
readonly TX_CANCELLED: "TxCancelled";
|
|
63
|
+
readonly TX_EXECUTED: "TxExecuted";
|
|
64
|
+
};
|
|
65
|
+
export type Event = typeof EVENTS[keyof typeof EVENTS];
|
|
66
|
+
//# sourceMappingURL=lib.index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lib.index.d.ts","sourceRoot":"","sources":["../../types/lib.index.tsx"],"names":[],"mappings":"AASA;;GAEG;AACH,eAAO,MAAM,QAAQ;;;;;;;;;CASX,CAAC;AAEX,MAAM,MAAM,QAAQ,GAAG,OAAO,QAAQ,CAAC,MAAM,OAAO,QAAQ,CAAC,CAAC;AAI9D,eAAO,MAAM,QAAQ;;;;;;;;;;CAUX,CAAC;AAEX,MAAM,MAAM,QAAQ,GAAG,OAAO,QAAQ,CAAC,MAAM,OAAO,QAAQ,CAAC,CAAC;AAE9D;;GAEG;AACH,eAAO,MAAM,kBAAkB;;;;;;;CAOrB,CAAC;AAEX,MAAM,MAAM,gBAAgB,GAAG,OAAO,kBAAkB,CAAC,MAAM,OAAO,kBAAkB,CAAC,CAAC;AAE1F;;GAEG;AACH,eAAO,MAAM,KAAK;;;;CAIR,CAAC;AAEX,MAAM,MAAM,IAAI,GAAG,OAAO,KAAK,CAAC,MAAM,OAAO,KAAK,CAAC,CAAC;AAEpD;;GAEG;AACH,eAAO,MAAM,WAAW;;;CAGd,CAAC;AAEX,MAAM,MAAM,QAAQ,GAAG,OAAO,WAAW,CAAC,MAAM,OAAO,WAAW,CAAC,CAAC;AAEpE;;GAEG;AACH,eAAO,MAAM,MAAM;;;;;CAKT,CAAC;AAEX,MAAM,MAAM,KAAK,GAAG,OAAO,MAAM,CAAC,MAAM,OAAO,MAAM,CAAC,CAAC"}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { keccak256 as k256, toHex } from 'viem';
|
|
2
|
+
/**
|
|
3
|
+
* Helper function to compute keccak256 of a string
|
|
4
|
+
*/
|
|
5
|
+
const keccak256 = (str) => {
|
|
6
|
+
return toHex(k256(new TextEncoder().encode(str)));
|
|
7
|
+
};
|
|
8
|
+
/**
|
|
9
|
+
* Enums and constants for EngineBlox
|
|
10
|
+
*/
|
|
11
|
+
export const TxStatus = {
|
|
12
|
+
UNDEFINED: 0,
|
|
13
|
+
PENDING: 1,
|
|
14
|
+
EXECUTING: 2,
|
|
15
|
+
PROCESSING_PAYMENT: 3,
|
|
16
|
+
CANCELLED: 4,
|
|
17
|
+
COMPLETED: 5,
|
|
18
|
+
FAILED: 6,
|
|
19
|
+
REJECTED: 7
|
|
20
|
+
};
|
|
21
|
+
// ExecutionType enum removed - use executionSelector (0x00000000 for simple ETH transfers) and executionParams directly
|
|
22
|
+
export const TxAction = {
|
|
23
|
+
EXECUTE_TIME_DELAY_REQUEST: 0,
|
|
24
|
+
EXECUTE_TIME_DELAY_APPROVE: 1,
|
|
25
|
+
EXECUTE_TIME_DELAY_CANCEL: 2,
|
|
26
|
+
SIGN_META_REQUEST_AND_APPROVE: 3,
|
|
27
|
+
SIGN_META_APPROVE: 4,
|
|
28
|
+
SIGN_META_CANCEL: 5,
|
|
29
|
+
EXECUTE_META_REQUEST_AND_APPROVE: 6,
|
|
30
|
+
EXECUTE_META_APPROVE: 7,
|
|
31
|
+
EXECUTE_META_CANCEL: 8
|
|
32
|
+
};
|
|
33
|
+
/**
|
|
34
|
+
* Constants for function selectors
|
|
35
|
+
*/
|
|
36
|
+
export const FUNCTION_SELECTORS = {
|
|
37
|
+
TX_REQUEST: keccak256("txRequest(address,address,uint256,uint256,bytes32,uint8,bytes)").slice(0, 10),
|
|
38
|
+
TX_DELAYED_APPROVAL: keccak256("txDelayedApproval(uint256)").slice(0, 10),
|
|
39
|
+
TX_CANCELLATION: keccak256("txCancellation(uint256)").slice(0, 10),
|
|
40
|
+
META_TX_APPROVAL: keccak256("txApprovalWithMetaTx((uint256,uint256,uint8,(address,address,uint256,uint256,bytes32,uint8,bytes),bytes32,bytes,(address,uint256,address,uint256)),(uint256,address,bytes4,uint256,uint256,uint256,address),bytes,bytes)").slice(0, 10),
|
|
41
|
+
META_TX_CANCELLATION: keccak256("txCancellationWithMetaTx((uint256,uint256,uint8,(address,address,uint256,uint256,bytes32,uint8,bytes),bytes32,bytes,(address,uint256,address,uint256)),(uint256,address,bytes4,uint256,uint256,uint256,address),bytes,bytes)").slice(0, 10),
|
|
42
|
+
META_TX_REQUEST_AND_APPROVE: keccak256("requestAndApprove((uint256,uint256,uint8,(address,address,uint256,uint256,bytes32,uint8,bytes),bytes32,bytes,(address,uint256,address,uint256)),(uint256,address,bytes4,uint256,uint256,uint256,address),bytes,bytes)").slice(0, 10)
|
|
43
|
+
};
|
|
44
|
+
/**
|
|
45
|
+
* Constants for roles
|
|
46
|
+
*/
|
|
47
|
+
export const ROLES = {
|
|
48
|
+
OWNER_ROLE: keccak256("OWNER_ROLE"),
|
|
49
|
+
BROADCASTER_ROLE: keccak256("BROADCASTER_ROLE"),
|
|
50
|
+
RECOVERY_ROLE: keccak256("RECOVERY_ROLE")
|
|
51
|
+
};
|
|
52
|
+
/**
|
|
53
|
+
* Constants for EIP-712 type hashes
|
|
54
|
+
*/
|
|
55
|
+
export const TYPE_HASHES = {
|
|
56
|
+
DOMAIN_SEPARATOR: keccak256("EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)"),
|
|
57
|
+
META_TRANSACTION: keccak256("MetaTransaction(TxRecord txRecord,MetaTxParams params,bytes data)TxRecord(uint256 txId,uint256 releaseTime,uint8 status,TxParams params,bytes32 message,bytes result,PaymentDetails payment)TxParams(address requester,address target,uint256 value,uint256 gasLimit,bytes32 operationType,bytes4 executionSelector,bytes executionParams)MetaTxParams(uint256 chainId,uint256 nonce,address handlerContract,bytes4 handlerSelector,uint8 action,uint256 deadline,uint256 maxGasPrice,address signer)PaymentDetails(address recipient,uint256 nativeTokenAmount,address erc20TokenAddress,uint256 erc20TokenAmount)")
|
|
58
|
+
};
|
|
59
|
+
/**
|
|
60
|
+
* Event names
|
|
61
|
+
*/
|
|
62
|
+
export const EVENTS = {
|
|
63
|
+
REQUESTED_TX: "RequestedTx",
|
|
64
|
+
TX_APPROVED: "TxApproved",
|
|
65
|
+
TX_CANCELLED: "TxCancelled",
|
|
66
|
+
TX_EXECUTED: "TxExecuted"
|
|
67
|
+
};
|
|
68
|
+
//# sourceMappingURL=lib.index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lib.index.js","sourceRoot":"","sources":["../../types/lib.index.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,IAAI,IAAI,EAAE,KAAK,EAAE,MAAM,MAAM,CAAC;AAEhD;;GAEG;AACH,MAAM,SAAS,GAAG,CAAC,GAAW,EAAU,EAAE;IACxC,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;AACpD,CAAC,CAAC;AAEF;;GAEG;AACH,MAAM,CAAC,MAAM,QAAQ,GAAG;IACtB,SAAS,EAAE,CAAC;IACZ,OAAO,EAAE,CAAC;IACV,SAAS,EAAE,CAAC;IACZ,kBAAkB,EAAE,CAAC;IACrB,SAAS,EAAE,CAAC;IACZ,SAAS,EAAE,CAAC;IACZ,MAAM,EAAE,CAAC;IACT,QAAQ,EAAE,CAAC;CACH,CAAC;AAIX,wHAAwH;AAExH,MAAM,CAAC,MAAM,QAAQ,GAAG;IACtB,0BAA0B,EAAE,CAAC;IAC7B,0BAA0B,EAAE,CAAC;IAC7B,yBAAyB,EAAE,CAAC;IAC5B,6BAA6B,EAAE,CAAC;IAChC,iBAAiB,EAAE,CAAC;IACpB,gBAAgB,EAAE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
|
|
1
|
+
import { TxAction } from '../types/lib.index';
|
|
2
|
+
/**
|
|
3
|
+
* Branded type for uint16 bitmap values (0-65535)
|
|
4
|
+
* This ensures type safety and prevents invalid bitmap values
|
|
5
|
+
*/
|
|
6
|
+
export type Uint16Bitmap = number & {
|
|
7
|
+
readonly __brand: 'Uint16Bitmap';
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* Validates and creates a Uint16Bitmap from a number
|
|
11
|
+
* @param value The number to validate and convert
|
|
12
|
+
* @returns A validated Uint16Bitmap
|
|
13
|
+
* @throws Error if value is outside 0..65535
|
|
14
|
+
*/
|
|
15
|
+
export declare function createUint16Bitmap(value: number): Uint16Bitmap;
|
|
16
|
+
/**
|
|
17
|
+
* Safely creates a Uint16Bitmap, clamping values outside the valid range
|
|
18
|
+
* @param value The number to validate and convert
|
|
19
|
+
* @returns A validated Uint16Bitmap (clamped to valid range)
|
|
20
|
+
*/
|
|
21
|
+
export declare function createUint16BitmapClamped(value: number): Uint16Bitmap;
|
|
22
|
+
/**
|
|
23
|
+
* Checks if a specific bit is set in the bitmap
|
|
24
|
+
* @param bitmap The uint16 bitmap
|
|
25
|
+
* @param bitIndex The bit index to check (0-15, corresponding to TxAction enum values)
|
|
26
|
+
* @returns True if the bit is set, false otherwise
|
|
27
|
+
*/
|
|
28
|
+
export declare function isBitSet(bitmap: Uint16Bitmap, bitIndex: number): boolean;
|
|
29
|
+
/**
|
|
30
|
+
* Sets a specific bit in the bitmap
|
|
31
|
+
* @param bitmap The uint16 bitmap
|
|
32
|
+
* @param bitIndex The bit index to set (0-15, corresponding to TxAction enum values)
|
|
33
|
+
* @returns A new Uint16Bitmap with the bit set
|
|
34
|
+
*/
|
|
35
|
+
export declare function setBit(bitmap: Uint16Bitmap, bitIndex: number): Uint16Bitmap;
|
|
36
|
+
/**
|
|
37
|
+
* Clears a specific bit in the bitmap
|
|
38
|
+
* @param bitmap The uint16 bitmap
|
|
39
|
+
* @param bitIndex The bit index to clear (0-15, corresponding to TxAction enum values)
|
|
40
|
+
* @returns A new Uint16Bitmap with the bit cleared
|
|
41
|
+
*/
|
|
42
|
+
export declare function clearBit(bitmap: Uint16Bitmap, bitIndex: number): Uint16Bitmap;
|
|
43
|
+
/**
|
|
44
|
+
* Gets the numeric value of the bitmap
|
|
45
|
+
* @param bitmap The uint16 bitmap
|
|
46
|
+
* @returns The numeric value (0-65535)
|
|
47
|
+
*/
|
|
48
|
+
export declare function getBitValue(bitmap: Uint16Bitmap): number;
|
|
49
|
+
/**
|
|
50
|
+
* Creates a bitmap from an array of TxAction values
|
|
51
|
+
* @param actions Array of TxAction enum values to set in the bitmap
|
|
52
|
+
* @returns A new Uint16Bitmap with the corresponding bits set
|
|
53
|
+
*/
|
|
54
|
+
export declare function createBitmapFromActions(actions: TxAction[]): Uint16Bitmap;
|
|
55
|
+
/**
|
|
56
|
+
* Converts a bitmap to an array of TxAction values
|
|
57
|
+
* @param bitmap The uint16 bitmap
|
|
58
|
+
* @returns Array of TxAction enum values that are set in the bitmap
|
|
59
|
+
*/
|
|
60
|
+
export declare function getActionsFromBitmap(bitmap: Uint16Bitmap): TxAction[];
|
|
61
|
+
/**
|
|
62
|
+
* Converts a number to Uint16Bitmap if it's a valid raw value from contract
|
|
63
|
+
* This is useful when receiving bitmap values from contract calls
|
|
64
|
+
* @param value The raw number value from contract
|
|
65
|
+
* @returns A validated Uint16Bitmap
|
|
66
|
+
*/
|
|
67
|
+
export declare function fromContractValue(value: number | bigint): Uint16Bitmap;
|
|
68
|
+
/**
|
|
69
|
+
* Converts a Uint16Bitmap to a plain number for contract calls
|
|
70
|
+
* This is useful when passing bitmap values to contract methods
|
|
71
|
+
* @param bitmap The Uint16Bitmap to convert
|
|
72
|
+
* @returns The numeric value (0-65535)
|
|
73
|
+
*/
|
|
74
|
+
export declare function toContractValue(bitmap: Uint16Bitmap): number;
|
|
75
|
+
//# sourceMappingURL=bitmap.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"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UINT16_MAX = 65535;
|
|
5
|
+
const UINT16_MIN = 0;
|
|
6
|
+
/**
|
|
7
|
+
* Validates and creates a Uint16Bitmap from a number
|
|
8
|
+
* @param value The number to validate and convert
|
|
9
|
+
* @returns A validated Uint16Bitmap
|
|
10
|
+
* @throws Error if value is outside 0..65535
|
|
11
|
+
*/
|
|
12
|
+
export function createUint16Bitmap(value) {
|
|
13
|
+
if (!Number.isInteger(value)) {
|
|
14
|
+
throw new Error(`Bitmap value must be an integer, got: ${value}`);
|
|
15
|
+
}
|
|
16
|
+
if (value < UINT16_MIN || value > UINT16_MAX) {
|
|
17
|
+
throw new Error(`Bitmap value must be between ${UINT16_MIN} and ${UINT16_MAX}, got: ${value}`);
|
|
18
|
+
}
|
|
19
|
+
return value;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Safely creates a Uint16Bitmap, clamping values outside the valid range
|
|
23
|
+
* @param value The number to validate and convert
|
|
24
|
+
* @returns A validated Uint16Bitmap (clamped to valid range)
|
|
25
|
+
*/
|
|
26
|
+
export function createUint16BitmapClamped(value) {
|
|
27
|
+
if (!Number.isInteger(value)) {
|
|
28
|
+
throw new Error(`Bitmap value must be an integer, got: ${value}`);
|
|
29
|
+
}
|
|
30
|
+
const clamped = Math.max(UINT16_MIN, Math.min(UINT16_MAX, value));
|
|
31
|
+
return clamped;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Checks if a specific bit is set in the bitmap
|
|
35
|
+
* @param bitmap The uint16 bitmap
|
|
36
|
+
* @param bitIndex The bit index to check (0-15, corresponding to TxAction enum values)
|
|
37
|
+
* @returns True if the bit is set, false otherwise
|
|
38
|
+
*/
|
|
39
|
+
export function isBitSet(bitmap, bitIndex) {
|
|
40
|
+
if (bitIndex < 0 || bitIndex > 15) {
|
|
41
|
+
throw new Error(`Bit index must be between 0 and 15, got: ${bitIndex}`);
|
|
42
|
+
}
|
|
43
|
+
return (bitmap & (1 << bitIndex)) !== 0;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Sets a specific bit in the bitmap
|
|
47
|
+
* @param bitmap The uint16 bitmap
|
|
48
|
+
* @param bitIndex The bit index to set (0-15, corresponding to TxAction enum values)
|
|
49
|
+
* @returns A new Uint16Bitmap with the bit set
|
|
50
|
+
*/
|
|
51
|
+
export function setBit(bitmap, bitIndex) {
|
|
52
|
+
if (bitIndex < 0 || bitIndex > 15) {
|
|
53
|
+
throw new Error(`Bit index must be between 0 and 15, got: ${bitIndex}`);
|
|
54
|
+
}
|
|
55
|
+
const newValue = bitmap | (1 << bitIndex);
|
|
56
|
+
return createUint16Bitmap(newValue);
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Clears a specific bit in the bitmap
|
|
60
|
+
* @param bitmap The uint16 bitmap
|
|
61
|
+
* @param bitIndex The bit index to clear (0-15, corresponding to TxAction enum values)
|
|
62
|
+
* @returns A new Uint16Bitmap with the bit cleared
|
|
63
|
+
*/
|
|
64
|
+
export function clearBit(bitmap, bitIndex) {
|
|
65
|
+
if (bitIndex < 0 || bitIndex > 15) {
|
|
66
|
+
throw new Error(`Bit index must be between 0 and 15, got: ${bitIndex}`);
|
|
67
|
+
}
|
|
68
|
+
const newValue = bitmap & ~(1 << bitIndex);
|
|
69
|
+
return createUint16Bitmap(newValue);
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Gets the numeric value of the bitmap
|
|
73
|
+
* @param bitmap The uint16 bitmap
|
|
74
|
+
* @returns The numeric value (0-65535)
|
|
75
|
+
*/
|
|
76
|
+
export function getBitValue(bitmap) {
|
|
77
|
+
return bitmap;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Creates a bitmap from an array of TxAction values
|
|
81
|
+
* @param actions Array of TxAction enum values to set in the bitmap
|
|
82
|
+
* @returns A new Uint16Bitmap with the corresponding bits set
|
|
83
|
+
*/
|
|
84
|
+
export function createBitmapFromActions(actions) {
|
|
85
|
+
let bitmap = createUint16Bitmap(0);
|
|
86
|
+
for (const action of actions) {
|
|
87
|
+
bitmap = setBit(bitmap, action);
|
|
88
|
+
}
|
|
89
|
+
return bitmap;
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Converts a bitmap to an array of TxAction values
|
|
93
|
+
* @param bitmap The uint16 bitmap
|
|
94
|
+
* @returns Array of TxAction enum values that are set in the bitmap
|
|
95
|
+
*/
|
|
96
|
+
export function getActionsFromBitmap(bitmap) {
|
|
97
|
+
const actions = [];
|
|
98
|
+
for (let i = 0; i <= 15; i++) {
|
|
99
|
+
if (isBitSet(bitmap, i)) {
|
|
100
|
+
actions.push(i);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
return actions;
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Converts a number to Uint16Bitmap if it's a valid raw value from contract
|
|
107
|
+
* This is useful when receiving bitmap values from contract calls
|
|
108
|
+
* @param value The raw number value from contract
|
|
109
|
+
* @returns A validated Uint16Bitmap
|
|
110
|
+
*/
|
|
111
|
+
export function fromContractValue(value) {
|
|
112
|
+
const numValue = typeof value === 'bigint' ? Number(value) : value;
|
|
113
|
+
return createUint16Bitmap(numValue);
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Converts a Uint16Bitmap to a plain number for contract calls
|
|
117
|
+
* This is useful when passing bitmap values to contract methods
|
|
118
|
+
* @param bitmap The Uint16Bitmap to convert
|
|
119
|
+
* @returns The numeric value (0-65535)
|
|
120
|
+
*/
|
|
121
|
+
export function toContractValue(bitmap) {
|
|
122
|
+
return getBitValue(bitmap);
|
|
123
|
+
}
|
|
124
|
+
//# sourceMappingURL=bitmap.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bitmap.js","sourceRoot":"","sources":["../../utils/bitmap.ts"],"names":[],"mappings":"AAQA;;GAEG;AACH,MAAM,UAAU,GAAG,KAAK,CAAC;AACzB,MAAM,UAAU,GAAG,CAAC,CAAC;AAErB;;;;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