@cashie/core-lib 1.0.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.
Files changed (68) hide show
  1. package/README.md +9 -0
  2. package/dist/abi/abi.d.ts +2620 -0
  3. package/dist/abi/index.d.ts +1 -0
  4. package/dist/backend/auth/index.d.ts +4 -0
  5. package/dist/backend/auth/jwt.types.d.ts +3 -0
  6. package/dist/backend/auth/ocap/ocap-build.d.ts +35 -0
  7. package/dist/backend/auth/ocap/ocap-types.d.ts +87 -0
  8. package/dist/backend/auth/siwe.types.d.ts +18 -0
  9. package/dist/backend/blockchain/index.d.ts +1 -0
  10. package/dist/backend/blockchain/types.d.ts +11 -0
  11. package/dist/backend/contracts/badge.types.d.ts +25 -0
  12. package/dist/backend/contracts/balance.types.d.ts +32 -0
  13. package/dist/backend/contracts/event.types.d.ts +34 -0
  14. package/dist/backend/contracts/index.d.ts +4 -0
  15. package/dist/backend/contracts/receipt.types.d.ts +55 -0
  16. package/dist/backend/index.d.ts +4 -0
  17. package/dist/backend/tx-tracking/index.d.ts +1 -0
  18. package/dist/backend/tx-tracking/types.d.ts +41 -0
  19. package/dist/client/index.d.ts +2 -0
  20. package/dist/client/payment-client.d.ts +30 -0
  21. package/dist/client/schemas.d.ts +55 -0
  22. package/dist/client/types.d.ts +163 -0
  23. package/dist/data/cashieDataUrl.d.ts +79 -0
  24. package/dist/data/encoder.d.ts +130 -0
  25. package/dist/data/index.d.ts +3 -0
  26. package/dist/data/types.d.ts +116 -0
  27. package/dist/erc-7715/common.types.d.ts +37 -0
  28. package/dist/erc-7715/index.d.ts +4 -0
  29. package/dist/erc-7715/permission/index.d.ts +2 -0
  30. package/dist/erc-7715/permission/schemas.d.ts +172 -0
  31. package/dist/erc-7715/permission/types.d.ts +27 -0
  32. package/dist/erc-7715/request/index.d.ts +2 -0
  33. package/dist/erc-7715/request/schemas.d.ts +260 -0
  34. package/dist/erc-7715/request/types.d.ts +47 -0
  35. package/dist/erc-7715/rules/index.d.ts +2 -0
  36. package/dist/erc-7715/rules/schemas.d.ts +76 -0
  37. package/dist/erc-7715/rules/types.d.ts +26 -0
  38. package/dist/identity/cashieIdentitySoulTypedData.d.ts +65 -0
  39. package/dist/identity/encoder.d.ts +24 -0
  40. package/dist/identity/index.d.ts +5 -0
  41. package/dist/identity/issuer/error/index.d.ts +1 -0
  42. package/dist/identity/issuer/error/plaidIdvErrors.d.ts +24 -0
  43. package/dist/identity/issuer/identity-issuer.d.ts +30 -0
  44. package/dist/identity/issuer/index.d.ts +3 -0
  45. package/dist/identity/issuer/types.d.ts +35 -0
  46. package/dist/identity/soul/index.d.ts +1 -0
  47. package/dist/identity/soul/soulManager.d.ts +63 -0
  48. package/dist/identity/types.d.ts +196 -0
  49. package/dist/index.cjs +2 -0
  50. package/dist/index.cjs.map +7 -0
  51. package/dist/index.d.ts +10 -0
  52. package/dist/index.mjs +2 -0
  53. package/dist/index.mjs.map +7 -0
  54. package/dist/intent/encoder.d.ts +22 -0
  55. package/dist/intent/index.d.ts +2 -0
  56. package/dist/intent/types.d.ts +88 -0
  57. package/dist/router/index.d.ts +1 -0
  58. package/dist/router/types.d.ts +12 -0
  59. package/dist/shared/either.d.ts +68 -0
  60. package/dist/shared/errorCode.d.ts +115 -0
  61. package/dist/shared/index.d.ts +3 -0
  62. package/dist/shared/types/eip-7702.types.d.ts +21 -0
  63. package/dist/shared/types/index.d.ts +3 -0
  64. package/dist/shared/types/payment-protocol.types.d.ts +17 -0
  65. package/dist/shared/types/rpc.types.d.ts +14 -0
  66. package/dist/utils/index.d.ts +1 -0
  67. package/dist/utils/utils.d.ts +17 -0
  68. package/package.json +67 -0
@@ -0,0 +1,22 @@
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.
4
+ */
5
+ import { Hex } from 'viem';
6
+ import { PaymentIntent } from './types.js';
7
+ /**
8
+ * Encodes a payment intent for hashing.
9
+ *
10
+ * dependencies, and identityMintPayloads are not encoded in the payment intent.
11
+ *
12
+ * @param paymentIntent - The payment intent to encode
13
+ * @returns The encoded payment intent as a hex string
14
+ */
15
+ export declare function encodePaymentIntent(paymentIntent: PaymentIntent): Hex;
16
+ /**
17
+ * Returns keccak256(encodePaymentIntent(paymentIntent)).
18
+ *
19
+ * @param paymentIntent - The payment intent to hash
20
+ * @returns The hash of the payment intent
21
+ */
22
+ export declare function getPaymentIntentHash(paymentIntent: PaymentIntent): `0x${string}`;
@@ -0,0 +1,2 @@
1
+ export * from './types.js';
2
+ export * from './encoder.js';
@@ -0,0 +1,88 @@
1
+ import { Address, Hex } from 'viem';
2
+ import { IdentityMintSignPayloadWithSignature } from '../identity/types.js';
3
+ export declare enum CashieRouterActions {
4
+ PAYMENT_C2B = "payment-c2b",
5
+ PAYMENT_B2B = "payment-b2b",
6
+ PAYMENT_B2C = "payment-b2c",
7
+ DEPOSIT = "deposit",
8
+ WITHDRAW = "withdraw"
9
+ }
10
+ export type RewardItem = {
11
+ recipient: Address;
12
+ rewardAmount: Hex;
13
+ rewardTokenAddress: Address;
14
+ };
15
+ export type RewardIntentDetails = {
16
+ /**
17
+ * The address of the payer of the reward.
18
+ */
19
+ rewardPayer: Address;
20
+ /**
21
+ * The reward items of the payment.
22
+ */
23
+ rewardItems: RewardItem[];
24
+ /**
25
+ * The ERC-7710 permission context used to redeem the reward.
26
+ */
27
+ rewardPermissionContext: Hex;
28
+ /**
29
+ * The delegation manager address.
30
+ */
31
+ rewardDelegationManager: Address;
32
+ };
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;
45
+ /**
46
+ * The address to send payment to.
47
+ */
48
+ recipient: Address;
49
+ /**
50
+ * The address of the payer of the payment.
51
+ */
52
+ payer: Address;
53
+ /**
54
+ * The identity mint payload with signature of the payment.
55
+ */
56
+ identityMintPayloads: IdentityMintSignPayloadWithSignature[];
57
+ /**
58
+ * The ERC20 token address(stablecoin address).
59
+ */
60
+ tokenAddress: Address;
61
+ /**
62
+ * The amount of the payment.
63
+ */
64
+ allowance: Hex;
65
+ /**
66
+ * The reward intent details of the payment.
67
+ */
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;
77
+ /**
78
+ * Optional but when present then fields for factory and factoryData are required as defined in ERC-4337.
79
+ */
80
+ dependencies: {
81
+ factory: Address;
82
+ factoryData: Hex;
83
+ }[];
84
+ /**
85
+ * The salt of the payment intent.
86
+ */
87
+ salt: Hex;
88
+ };
@@ -0,0 +1 @@
1
+ export * from './types.js';
@@ -0,0 +1,12 @@
1
+ import { ReceiptType } from '../data/index.js';
2
+ import { Hex } from 'viem';
3
+ export type ReceiptBadgeRouterMintPayload = {
4
+ /**
5
+ * The salt of the receipt
6
+ */
7
+ salt: Hex;
8
+ /**
9
+ * The type of the receipt
10
+ */
11
+ receiptType: ReceiptType;
12
+ };
@@ -0,0 +1,68 @@
1
+ export declare abstract class Either<L, R> {
2
+ protected value: L | R;
3
+ constructor(value: L | R);
4
+ /**
5
+ * Transforms the value in a `Right`, does nothing for a `Left`.
6
+ */
7
+ abstract map<U>(f: (value: R) => U): Either<L, U>;
8
+ /**
9
+ * Chains computations that return an `Either`.
10
+ * Propagates `Left` if the current value is `Left`.
11
+ */
12
+ abstract flatMap<U>(f: (value: R) => Either<L, U>): Either<L, U>;
13
+ /**
14
+ * Returns the value inside a `Right` or the provided default value if `Left`.
15
+ */
16
+ abstract getOrElse(defaultValue: R): R;
17
+ /**
18
+ * Determines if the instance is `Left`.
19
+ */
20
+ abstract isLeft(): boolean;
21
+ /**
22
+ * Determines if the instance is `Right`.
23
+ */
24
+ abstract isRight(): boolean;
25
+ /**
26
+ * Returns a string representation of the instance.
27
+ *
28
+ * @returns A string representation of the instance.
29
+ */
30
+ toString(): string;
31
+ /**
32
+ * Handles both `Left` and `Right` cases with provided functions.
33
+ *
34
+ * @param onLeft - Function to handle `Left`.
35
+ * @param onRight - Function to handle `Right`.
36
+ * @returns The result of the function that matches the instance.
37
+ */
38
+ fold<U>(onLeft: (error: L) => U, onRight: (value: R) => U): U;
39
+ foldAsync<U>(onLeft: (error: L) => Promise<U>, onRight: (value: R) => Promise<U>): Promise<U>;
40
+ /**
41
+ * Factory method for creating a `Right` instance.
42
+ *
43
+ * @param value - The value to wrap in a `Right`.
44
+ * @returns A `Right` instance.
45
+ */
46
+ static of<R>(value: R): Either<never, R>;
47
+ /**
48
+ * Factory method for creating a `Left` instance.
49
+ *
50
+ * @param value - The value to wrap in a `Left`.
51
+ * @returns A `Left` instance.
52
+ */
53
+ static Left<L, R>(value: L): Either<L, R>;
54
+ /**
55
+ * Factory method for creating a `Right` instance.
56
+ *
57
+ * @param value - The value to wrap in a `Right`.
58
+ * @returns A `Right` instance.
59
+ */
60
+ static Right<L, R>(value: R): Either<L, R>;
61
+ }
62
+ /**
63
+ * Determines if the provided value is an instance of `Either`.
64
+ *
65
+ * @param value - The value to check.
66
+ * @returns `true` if the value is an instance of `Either`, `false` otherwise.
67
+ */
68
+ export declare const isEither: <L>(value: unknown) => value is Either<L, unknown>;
@@ -0,0 +1,115 @@
1
+ export type ErrorDetails = {
2
+ code: number;
3
+ message: string;
4
+ };
5
+ /**
6
+ * The EIP1193 error code enum
7
+ */
8
+ export declare enum EIP1193_ERROR_CODES {
9
+ /**
10
+ * The user rejected the request.
11
+ */
12
+ USER_REJECTED_REQUEST = 4001,
13
+ /**
14
+ * The specified address is not connected or not in the wallet
15
+ */
16
+ UNAUTHORIZED_ACCESS_ACCOUNT = 4100,
17
+ /**
18
+ * The Provider does not support the requested method.
19
+ */
20
+ UNSUPPORTED_METHOD = 4200,
21
+ /**
22
+ * The Provider is disconnected from all chains.
23
+ */
24
+ DISCONNECTED = 4900,
25
+ /**
26
+ * The Provider is not connected to the requested chain.
27
+ */
28
+ CHAIN_DISCONNECTED = 4901
29
+ }
30
+ /**
31
+ * The EIP5792 error code enum
32
+ */
33
+ export declare enum EIP5792_ERROR_CODES {
34
+ /**
35
+ * This wallet does not support a capability that was not marked as optional
36
+ * Related RPCs: wallet_sendCalls
37
+ */
38
+ UNSUPPORTED_NON_OPTIONAL_CAPABILITY = 5700,
39
+ /**
40
+ * This wallet does not support the specified chain id
41
+ * Related RPCs: wallet_sendCalls
42
+ */
43
+ UNSUPPORTED_CHAIN_ID = 5710,
44
+ /**
45
+ * There is already a bundle submitted with this id
46
+ * Related RPCs: wallet_sendCalls
47
+ */
48
+ DUPLICATE_BUNDLE_ID = 5720,
49
+ /**
50
+ * This bundle id is unknown / has not been submitted
51
+ * Related RPCs: wallet_getCallsStatus, wallet_showCallsStatus
52
+ */
53
+ UNKNOWN_BUNDLE_ID = 5730,
54
+ /**
55
+ * The call bundle is too large for the wallet to process
56
+ * Related RPCs: wallet_sendCalls
57
+ */
58
+ BUNDLE_TOO_LARGE = 5740,
59
+ /**
60
+ * The wallet can support atomicity after an upgrade, but the user rejected the upgrade
61
+ * Related RPCs: wallet_sendCalls
62
+ */
63
+ ATOMIC_READY_WALLET_REJECTED_UPGRADE = 5750,
64
+ /**
65
+ * The wallet does not support atomic execution but the request requires it
66
+ * Related RPCs: wallet_sendCalls
67
+ */
68
+ ATOMICITY_NOT_SUPPORTED = 5760
69
+ }
70
+ /**
71
+ * The ERC-7715 error code enum
72
+ */
73
+ export declare enum ERC7715_ERROR_CODES {
74
+ /**
75
+ * The specified method is not authorized for the given origin
76
+ * Related RPCs:
77
+ */
78
+ UNAUTHORIZED_ACCESS_RESTRICTED_METHOD = 4101
79
+ }
80
+ /**
81
+ * The fatal error code enum
82
+ */
83
+ export declare enum FATAL_ERROR_CODES {
84
+ INTERNAL_ERROR = -32001,
85
+ NO_SECURE_CONNECTION_ESTABLISHED = -32002
86
+ }
87
+ export declare enum COMMON_ERROR_CODES {
88
+ INVALID_PARAMS = -32602
89
+ }
90
+ /**
91
+ * Get the error message for a given error code
92
+ *
93
+ * @param code - The error code
94
+ * @returns The error message
95
+ * @throws An error if the error code is not found
96
+ */
97
+ export declare const getErrorMessage: (code: EIP1193_ERROR_CODES | EIP5792_ERROR_CODES | ERC7715_ERROR_CODES | FATAL_ERROR_CODES | COMMON_ERROR_CODES) => ErrorDetails;
98
+ export declare class RpcError extends Error {
99
+ /**
100
+ * MUST be an integer number
101
+ * SHOULD adhere to the specifications in the Error Standards section below
102
+ *
103
+ * @see https://eips.ethereum.org/EIPS/eip-1193#error-standards
104
+ */
105
+ code: number;
106
+ /**
107
+ * SHOULD contain any other useful information about the error
108
+ */
109
+ data?: unknown;
110
+ constructor({ message, code, data, }: {
111
+ message: string;
112
+ code: number;
113
+ data?: unknown;
114
+ });
115
+ }
@@ -0,0 +1,3 @@
1
+ export * from './errorCode.js';
2
+ export * from './either.js';
3
+ export * from './types/index.js';
@@ -0,0 +1,21 @@
1
+ import { Hex, Address } from 'viem';
2
+ export type CashieSigned7702Authorization = {
3
+ /** The r component of the signature */
4
+ r: Hex;
5
+ /** The s component of the signature. */
6
+ s: Hex;
7
+ /** The v component of the signature. */
8
+ v: number;
9
+ /** The y-parity value of the signature. */
10
+ yParity: number;
11
+ /** Address of the contract to delegate to. */
12
+ address: Address;
13
+ /** Chain ID. */
14
+ chainId: Hex;
15
+ /** Nonce of the EOA to delegate to. */
16
+ nonceHex: Hex;
17
+ metadata: {
18
+ /** The address of the EOA that signed the authorization. */
19
+ eoaAddress: Address;
20
+ };
21
+ };
@@ -0,0 +1,3 @@
1
+ export * from './rpc.types.js';
2
+ export * from './payment-protocol.types.js';
3
+ export * from './eip-7702.types.js';
@@ -0,0 +1,17 @@
1
+ /**
2
+ * The account type for a Cashie account
3
+ */
4
+ export declare enum CashieAccountType {
5
+ /**
6
+ * (Default) The individual account type
7
+ */
8
+ INDIVIDUAL = 0,
9
+ /**
10
+ * The business account type
11
+ */
12
+ BUSINESS = 1
13
+ }
14
+ /**
15
+ * The labels for the Cashie account types
16
+ */
17
+ export declare const CASHIE_ACCOUNT_TYPE_LABELS: Record<CashieAccountType, string>;
@@ -0,0 +1,14 @@
1
+ /**
2
+ * The JSON-RPC request object.
3
+ */
4
+ export type JsonRpcRequest = {
5
+ jsonrpc: '2.0';
6
+ method: string;
7
+ params: unknown[];
8
+ id: number | string;
9
+ };
10
+ /**
11
+ * Same-origin proxy for protocol-chain JSON-RPC. The browser must use this path
12
+ * instead of a public RPC URL so server RPC credentials stay off the client.
13
+ */
14
+ export declare const PROTOCOL_RPC_PROXY_PATH = "/api/public/protocol-rpc";
@@ -0,0 +1 @@
1
+ export * from './utils.js';
@@ -0,0 +1,17 @@
1
+ import { Hex } from 'viem';
2
+ /**
3
+ * Generates a random salt for the payment intent.
4
+ *
5
+ * @returns The random salt as a hex string.
6
+ */
7
+ export declare function generateSalt(): Hex;
8
+ /**
9
+ * Assert that the URL starts with https or http
10
+ *
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
15
+ * @returns the URL`
16
+ */
17
+ export declare function assertUrl(url: string): string;
package/package.json ADDED
@@ -0,0 +1,67 @@
1
+ {
2
+ "name": "@cashie/core-lib",
3
+ "version": "1.0.0",
4
+ "description": "A core library for the Cashie Protocol",
5
+ "homepage": "https://github.com/transeptorlabs/cashie-core/blob/main/packages/core-lib/README.md",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://github.com/transeptorlabs/cashie-core.git"
9
+ },
10
+ "bugs": {
11
+ "url": "https://github.com/transeptorlabs/cashie-core/issues"
12
+ },
13
+ "license": "MIT",
14
+ "author": "Transeptor Labs",
15
+ "type": "module",
16
+ "main": "dist/index.cjs",
17
+ "module": "dist/index.mjs",
18
+ "types": "dist/index.d.ts",
19
+ "exports": {
20
+ "require": {
21
+ "types": "./dist/index.d.ts",
22
+ "default": "./dist/index.cjs"
23
+ },
24
+ "import": {
25
+ "types": "./dist/index.d.ts",
26
+ "default": "./dist/index.mjs"
27
+ }
28
+ },
29
+ "files": [
30
+ "dist"
31
+ ],
32
+ "scripts": {
33
+ "build": "yarn build:esbuild && yarn build:types",
34
+ "build:esbuild": "node ./build-package.mjs",
35
+ "build:types": "tsc --emitDeclarationOnly",
36
+ "build:docs": "typedoc",
37
+ "build:pack": "yarn build && yarn pack --filename ../../deps/cashie-core-lib-0.0.0.tgz",
38
+ "generate:abis": "node ./scripts/generate-abis.mjs",
39
+ "generate:abis:build": "node ./scripts/generate-abis.mjs --build",
40
+ "generate:abis:check": "node ./scripts/generate-abis.mjs --check",
41
+ "lint:eslint": "eslint . --ext ts --cache",
42
+ "lint:dependencies": "yarn dedupe",
43
+ "lint:misc": "prettier '**/*.json' '**/*.md' '**/*.yml' '!**/CHANGELOG.md' '!.yarnrc.yml' --ignore-path .gitignore --no-error-on-unmatched-pattern",
44
+ "lint": "yarn lint:eslint && yarn lint:misc --check && yarn lint:dependencies --check",
45
+ "lint:fix": "yarn lint:eslint --fix && yarn lint:misc --write && yarn lint:dependencies",
46
+ "test": "vitest run --config ./vitest.config.ts --coverage",
47
+ "test:watch": "vitest --config ./vitest.config.ts"
48
+ },
49
+ "dependencies": {
50
+ "uuid": "9.0.1",
51
+ "viem": "2.37.3",
52
+ "zod": "4.1.11"
53
+ },
54
+ "devDependencies": {
55
+ "@types/node": "20.10.0",
56
+ "@types/uuid": "9.0.7",
57
+ "typescript": "5.6.3"
58
+ },
59
+ "engines": {
60
+ "node": ">=22.14.0"
61
+ },
62
+ "packageManager": "yarn@4.7.0",
63
+ "publishConfig": {
64
+ "access": "public",
65
+ "registry": "https://registry.npmjs.org/"
66
+ }
67
+ }