@cashie/core-lib 1.1.0 → 1.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,22 +1,39 @@
1
1
  /**
2
- * Canonical intent encoding for stable `paymentIntentHash` (Redis, APIs, optional router event arg).
3
- * AA orchestration and full {@link PaymentIntent} payloads stay in the node/wallet layer.
2
+ * Canonical intent encoding for a stable `intentHash` (Redis, APIs, optional
3
+ * router event arg). `data` is encoded per action so hashes cannot collide
4
+ * across actions. AA orchestration fields stay in the node/wallet layer.
4
5
  */
5
6
  import { Hex } from 'viem';
6
- import { PaymentIntent } from './types.js';
7
+ import { Intent, IntentActions } from './types.js';
7
8
  /**
8
- * Encodes a payment intent for hashing.
9
+ * Encodes intent `data` for hashing. Encoding is action-specific so data
10
+ * hashes cannot collide across actions.
9
11
  *
10
- * dependencies, and identityMintPayloads are not encoded in the payment intent.
12
+ * @param intent - The intent whose data to encode
13
+ * @returns The encoded data as a hex string
14
+ */
15
+ export declare function encodeIntentData<TIntentAction extends IntentActions>(intent: Intent<TIntentAction>): Hex;
16
+ /**
17
+ * Returns keccak256(encodeIntentData(intent)).
18
+ *
19
+ * @param intent - The intent whose data to hash
20
+ * @returns The hash of the action-specific data
21
+ */
22
+ export declare function getIntentDataHash<TIntentAction extends IntentActions>(intent: Intent<TIntentAction>): `0x${string}`;
23
+ /**
24
+ * Encodes an intent for hashing.
25
+ *
26
+ * permissionContext is not encoded. `data` is hashed per action and included
27
+ * as `dataHash`.
11
28
  *
12
- * @param paymentIntent - The payment intent to encode
13
- * @returns The encoded payment intent as a hex string
29
+ * @param intent - The intent to encode
30
+ * @returns The encoded intent as a hex string
14
31
  */
15
- export declare function encodePaymentIntent(paymentIntent: PaymentIntent): Hex;
32
+ export declare function encodeIntent<TIntentAction extends IntentActions>(intent: Intent<TIntentAction>): Hex;
16
33
  /**
17
- * Returns keccak256(encodePaymentIntent(paymentIntent)).
34
+ * Returns keccak256(encodeIntent(intent)).
18
35
  *
19
- * @param paymentIntent - The payment intent to hash
20
- * @returns The hash of the payment intent
36
+ * @param intent - The intent to hash
37
+ * @returns The hash of the intent
21
38
  */
22
- export declare function getPaymentIntentHash(paymentIntent: PaymentIntent): `0x${string}`;
39
+ export declare function getIntentHash<TIntentAction extends IntentActions>(intent: Intent<TIntentAction>): Hex;
@@ -1,18 +1,34 @@
1
1
  import { Address, Hex } from 'viem';
2
2
  import { IdentityMintSignPayloadWithSignature } from '../identity/types.js';
3
- export declare enum CashieRouterActions {
3
+ export declare enum PaymentIntentActions {
4
4
  PAYMENT_C2B = "payment-c2b",
5
5
  PAYMENT_B2B = "payment-b2b",
6
6
  PAYMENT_B2C = "payment-b2c",
7
7
  DEPOSIT = "deposit",
8
8
  WITHDRAW = "withdraw"
9
9
  }
10
+ export declare enum AccountIntentActions {
11
+ DEACTIVATE_ACCOUNT = "deactivate-account",
12
+ RECOVER_ACCOUNT = "recover-account",
13
+ FREEZE_ACCOUNT = "freeze-account"
14
+ }
15
+ export declare const IntentActions: {
16
+ readonly DEACTIVATE_ACCOUNT: AccountIntentActions.DEACTIVATE_ACCOUNT;
17
+ readonly RECOVER_ACCOUNT: AccountIntentActions.RECOVER_ACCOUNT;
18
+ readonly FREEZE_ACCOUNT: AccountIntentActions.FREEZE_ACCOUNT;
19
+ readonly PAYMENT_C2B: PaymentIntentActions.PAYMENT_C2B;
20
+ readonly PAYMENT_B2B: PaymentIntentActions.PAYMENT_B2B;
21
+ readonly PAYMENT_B2C: PaymentIntentActions.PAYMENT_B2C;
22
+ readonly DEPOSIT: PaymentIntentActions.DEPOSIT;
23
+ readonly WITHDRAW: PaymentIntentActions.WITHDRAW;
24
+ };
25
+ export type IntentActions = PaymentIntentActions | AccountIntentActions;
10
26
  export type RewardItem = {
11
27
  recipient: Address;
12
28
  rewardAmount: Hex;
13
29
  rewardTokenAddress: Address;
14
30
  };
15
- export type RewardIntentDetails = {
31
+ export type RewardData = {
16
32
  /**
17
33
  * The address of the payer of the reward.
18
34
  */
@@ -30,18 +46,7 @@ export type RewardIntentDetails = {
30
46
  */
31
47
  rewardDelegationManager: Address;
32
48
  };
33
- /**
34
- * RPC payload for executing a payment intent
35
- */
36
- export type PaymentIntent = {
37
- /**
38
- * The action of the payment intent.
39
- */
40
- action: CashieRouterActions;
41
- /**
42
- * hex-encoding of uint256
43
- */
44
- chainId: Hex;
49
+ export type PaymentIntentData = {
45
50
  /**
46
51
  * The address to send payment to.
47
52
  */
@@ -65,15 +70,7 @@ export type PaymentIntent = {
65
70
  /**
66
71
  * The reward intent details of the payment.
67
72
  */
68
- rewardIntentDetails?: RewardIntentDetails;
69
- /**
70
- * The ERC-7710 permission context used to redeem the payment.
71
- */
72
- permissionContext: Hex;
73
- /**
74
- * The delegation manager address.
75
- */
76
- delegationManager: Address;
73
+ rewardData?: RewardData;
77
74
  /**
78
75
  * Optional but when present then fields for factory and factoryData are required as defined in ERC-4337.
79
76
  */
@@ -81,8 +78,54 @@ export type PaymentIntent = {
81
78
  factory: Address;
82
79
  factoryData: Hex;
83
80
  }[];
81
+ };
82
+ type BaseAccountData = {
83
+ accountAddress: Address;
84
+ };
85
+ export type IntentDataMapping = {
86
+ [IntentActions.PAYMENT_C2B]: PaymentIntentData;
87
+ [IntentActions.PAYMENT_B2B]: PaymentIntentData;
88
+ [IntentActions.PAYMENT_B2C]: PaymentIntentData;
89
+ [IntentActions.DEPOSIT]: PaymentIntentData;
90
+ [IntentActions.WITHDRAW]: PaymentIntentData;
91
+ [IntentActions.DEACTIVATE_ACCOUNT]: BaseAccountData & {
92
+ permissionContexts: Hex[];
93
+ };
94
+ [IntentActions.RECOVER_ACCOUNT]: BaseAccountData;
95
+ [IntentActions.FREEZE_ACCOUNT]: BaseAccountData & {
96
+ /**
97
+ * The timestamp the account will stay frozen until. (unix timestamp in seconds)
98
+ */
99
+ timestamp: number;
100
+ };
101
+ };
102
+ /**
103
+ * RPC payload for executing a intent
104
+ */
105
+ export type Intent<TIntentAction extends IntentActions> = {
106
+ /**
107
+ * The action of the intent.
108
+ */
109
+ action: TIntentAction;
110
+ /**
111
+ * hex-encoding of uint256
112
+ */
113
+ chainId: Hex;
84
114
  /**
85
115
  * The salt of the payment intent.
86
116
  */
87
117
  salt: Hex;
118
+ /**
119
+ * The ERC-7710 permission context used to redeem the intent.
120
+ */
121
+ permissionContext: Hex;
122
+ /**
123
+ * The ERC-7710 delegation manager address.
124
+ */
125
+ delegationManager: Address;
126
+ /**
127
+ * The data of the intent.
128
+ */
129
+ data: IntentDataMapping[TIntentAction];
88
130
  };
131
+ export {};
@@ -92,7 +92,7 @@ export declare enum COMMON_ERROR_CODES {
92
92
  *
93
93
  * @param code - The error code
94
94
  * @returns The error message
95
- * @throws An error if the error code is not found
95
+ * @throws {Error} if the error code is not found
96
96
  */
97
97
  export declare const getErrorMessage: (code: EIP1193_ERROR_CODES | EIP5792_ERROR_CODES | ERC7715_ERROR_CODES | FATAL_ERROR_CODES | COMMON_ERROR_CODES) => ErrorDetails;
98
98
  export declare class RpcError extends Error {
@@ -9,9 +9,9 @@ export declare function generateSalt(): Hex;
9
9
  * Assert that the URL starts with https or http
10
10
  *
11
11
  * @param url - The URL to assert.
12
- * @throws an error if the URL is required
13
- * @throws an error if the URL does not start with https or http
14
- * @throws an error if the URL is not a valid URL
12
+ * @throws {Error} if the URL is required
13
+ * @throws {Error} if the URL does not start with https or http
14
+ * @throws {Error} if the URL is not a valid URL
15
15
  * @returns the URL`
16
16
  */
17
17
  export declare function assertUrl(url: string): string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cashie/core-lib",
3
- "version": "1.1.0",
3
+ "version": "1.3.0",
4
4
  "description": "A core library for the Cashie Protocol",
5
5
  "homepage": "https://github.com/transeptorlabs/cashie-core/blob/main/packages/core-lib/README.md",
6
6
  "repository": {
@@ -38,7 +38,7 @@
38
38
  "generate:abis": "node ./scripts/generate-abis.mjs",
39
39
  "generate:abis:build": "node ./scripts/generate-abis.mjs --build",
40
40
  "generate:abis:check": "node ./scripts/generate-abis.mjs --check",
41
- "lint:eslint": "eslint . --ext ts --cache",
41
+ "lint:eslint": "yarn run -T eslint . --cache",
42
42
  "lint:dependencies": "yarn dedupe",
43
43
  "lint:misc": "prettier '**/*.json' '**/*.md' '**/*.yml' '!**/CHANGELOG.md' '!.yarnrc.yml' --ignore-path .gitignore --no-error-on-unmatched-pattern",
44
44
  "lint": "yarn lint:eslint && yarn lint:misc --check && yarn lint:dependencies --check",
@@ -47,7 +47,7 @@
47
47
  "test:watch": "vitest --config ./vitest.config.ts"
48
48
  },
49
49
  "dependencies": {
50
- "uuid": "9.0.1",
50
+ "uuid": "14.0.0",
51
51
  "viem": "2.37.3",
52
52
  "zod": "4.1.11"
53
53
  },