@charterlabs/rhinestone-sdk 0.1.0 → 0.1.2

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 (194) hide show
  1. package/README.md +74 -181
  2. package/dist/src/accounts/error.d.ts +69 -0
  3. package/dist/src/accounts/error.d.ts.map +1 -0
  4. package/dist/src/accounts/error.js +109 -0
  5. package/dist/{accounts → src/accounts}/index.d.ts +14 -21
  6. package/dist/src/accounts/index.d.ts.map +1 -0
  7. package/dist/src/accounts/index.js +469 -0
  8. package/dist/src/accounts/index.test.d.ts +2 -0
  9. package/dist/src/accounts/index.test.d.ts.map +1 -0
  10. package/dist/src/accounts/index.test.js +36 -0
  11. package/dist/{accounts → src/accounts}/kernel.d.ts +7 -9
  12. package/dist/src/accounts/kernel.d.ts.map +1 -0
  13. package/dist/{accounts → src/accounts}/kernel.js +0 -8
  14. package/dist/src/accounts/kernel.test.d.ts +2 -0
  15. package/dist/src/accounts/kernel.test.d.ts.map +1 -0
  16. package/dist/src/accounts/kernel.test.js +105 -0
  17. package/dist/{accounts → src/accounts}/nexus.d.ts +14 -13
  18. package/dist/src/accounts/nexus.d.ts.map +1 -0
  19. package/dist/{accounts → src/accounts}/nexus.js +92 -88
  20. package/dist/src/accounts/nexus.test.d.ts +2 -0
  21. package/dist/src/accounts/nexus.test.d.ts.map +1 -0
  22. package/dist/src/accounts/nexus.test.js +87 -0
  23. package/dist/{accounts → src/accounts}/safe.d.ts +4 -6
  24. package/dist/src/accounts/safe.d.ts.map +1 -0
  25. package/dist/{accounts → src/accounts}/safe.js +20 -29
  26. package/dist/src/accounts/safe.test.d.ts +2 -0
  27. package/dist/src/accounts/safe.test.d.ts.map +1 -0
  28. package/dist/src/accounts/safe.test.js +87 -0
  29. package/dist/src/accounts/startale.d.ts +20 -0
  30. package/dist/src/accounts/startale.d.ts.map +1 -0
  31. package/dist/src/accounts/startale.js +100 -0
  32. package/dist/src/accounts/startale.test.d.ts +2 -0
  33. package/dist/src/accounts/startale.test.d.ts.map +1 -0
  34. package/dist/src/accounts/startale.test.js +99 -0
  35. package/dist/{accounts → src/accounts}/utils.d.ts +4 -3
  36. package/dist/src/accounts/utils.d.ts.map +1 -0
  37. package/dist/{accounts → src/accounts}/utils.js +44 -0
  38. package/dist/src/accounts/utils.test.d.ts +2 -0
  39. package/dist/src/accounts/utils.test.d.ts.map +1 -0
  40. package/dist/src/accounts/utils.test.js +49 -0
  41. package/dist/src/actions/index.d.ts +39 -0
  42. package/dist/src/actions/index.d.ts.map +1 -0
  43. package/dist/{actions → src/actions}/index.js +108 -15
  44. package/dist/src/actions/index.test.d.ts +2 -0
  45. package/dist/src/actions/index.test.d.ts.map +1 -0
  46. package/dist/src/actions/index.test.js +302 -0
  47. package/dist/{actions → src/actions}/smart-session.d.ts +2 -2
  48. package/dist/src/actions/smart-session.d.ts.map +1 -0
  49. package/dist/src/execution/compact.d.ts +8 -0
  50. package/dist/src/execution/compact.d.ts.map +1 -0
  51. package/dist/src/execution/compact.js +105 -0
  52. package/dist/src/execution/error.d.ts +54 -0
  53. package/dist/src/execution/error.d.ts.map +1 -0
  54. package/dist/src/execution/error.js +78 -0
  55. package/dist/{execution → src/execution}/index.d.ts +7 -6
  56. package/dist/src/execution/index.d.ts.map +1 -0
  57. package/dist/src/execution/index.js +150 -0
  58. package/dist/src/execution/smart-session.d.ts +15 -0
  59. package/dist/src/execution/smart-session.d.ts.map +1 -0
  60. package/dist/{execution → src/execution}/smart-session.js +16 -77
  61. package/dist/src/execution/smart-session.test.d.ts +2 -0
  62. package/dist/src/execution/smart-session.test.d.ts.map +1 -0
  63. package/dist/src/execution/smart-session.test.js +34 -0
  64. package/dist/src/execution/utils.d.ts +45 -0
  65. package/dist/src/execution/utils.d.ts.map +1 -0
  66. package/dist/src/execution/utils.js +433 -0
  67. package/dist/src/index.d.ts +41 -0
  68. package/dist/src/index.d.ts.map +1 -0
  69. package/dist/src/index.js +154 -0
  70. package/dist/src/modules/abi/smart-sessions.d.ts.map +1 -0
  71. package/dist/src/modules/common.d.ts.map +1 -0
  72. package/dist/{modules → src/modules}/index.d.ts +3 -11
  73. package/dist/src/modules/index.d.ts.map +1 -0
  74. package/dist/{modules → src/modules}/index.js +3 -45
  75. package/dist/src/modules/index.test.d.ts +2 -0
  76. package/dist/src/modules/index.test.d.ts.map +1 -0
  77. package/dist/src/modules/index.test.js +107 -0
  78. package/dist/src/modules/omni-account.d.ts +7 -0
  79. package/dist/src/modules/omni-account.d.ts.map +1 -0
  80. package/dist/src/modules/omni-account.js +11 -0
  81. package/dist/src/modules/read.d.ts +9 -0
  82. package/dist/src/modules/read.d.ts.map +1 -0
  83. package/dist/{modules → src/modules}/read.js +6 -37
  84. package/dist/{modules → src/modules}/validators/core.d.ts +6 -7
  85. package/dist/src/modules/validators/core.d.ts.map +1 -0
  86. package/dist/{modules → src/modules}/validators/core.js +83 -8
  87. package/dist/src/modules/validators/core.test.d.ts +2 -0
  88. package/dist/src/modules/validators/core.test.d.ts.map +1 -0
  89. package/dist/src/modules/validators/core.test.js +108 -0
  90. package/dist/src/modules/validators/index.d.ts +4 -0
  91. package/dist/src/modules/validators/index.d.ts.map +1 -0
  92. package/dist/{modules → src/modules}/validators/index.js +1 -3
  93. package/dist/{modules → src/modules}/validators/smart-sessions.d.ts +4 -15
  94. package/dist/src/modules/validators/smart-sessions.d.ts.map +1 -0
  95. package/dist/{modules → src/modules}/validators/smart-sessions.js +7 -61
  96. package/dist/src/modules/validators/smart-sessions.test.d.ts +2 -0
  97. package/dist/src/modules/validators/smart-sessions.test.d.ts.map +1 -0
  98. package/dist/src/modules/validators/smart-sessions.test.js +226 -0
  99. package/dist/src/orchestrator/client.d.ts +21 -0
  100. package/dist/src/orchestrator/client.d.ts.map +1 -0
  101. package/dist/src/orchestrator/client.js +284 -0
  102. package/dist/src/orchestrator/consts.d.ts +5 -0
  103. package/dist/src/orchestrator/consts.d.ts.map +1 -0
  104. package/dist/src/orchestrator/consts.js +9 -0
  105. package/dist/src/orchestrator/error.d.ts +96 -0
  106. package/dist/src/orchestrator/error.d.ts.map +1 -0
  107. package/dist/src/orchestrator/error.js +132 -0
  108. package/dist/src/orchestrator/index.d.ts +11 -0
  109. package/dist/src/orchestrator/index.d.ts.map +1 -0
  110. package/dist/src/orchestrator/index.js +42 -0
  111. package/dist/src/orchestrator/registry.d.ts +39 -0
  112. package/dist/src/orchestrator/registry.d.ts.map +1 -0
  113. package/dist/src/orchestrator/registry.js +121 -0
  114. package/dist/src/orchestrator/registry.json +365 -0
  115. package/dist/src/orchestrator/registry.test.d.ts +2 -0
  116. package/dist/src/orchestrator/registry.test.d.ts.map +1 -0
  117. package/dist/src/orchestrator/registry.test.js +137 -0
  118. package/dist/src/orchestrator/types.d.ts +275 -0
  119. package/dist/src/orchestrator/types.d.ts.map +1 -0
  120. package/dist/src/orchestrator/types.js +19 -0
  121. package/dist/src/orchestrator/utils.d.ts +5 -0
  122. package/dist/src/orchestrator/utils.d.ts.map +1 -0
  123. package/dist/src/orchestrator/utils.js +126 -0
  124. package/dist/{types.d.ts → src/types.d.ts} +42 -21
  125. package/dist/src/types.d.ts.map +1 -0
  126. package/dist/test/consts.d.ts +10 -0
  127. package/dist/test/consts.d.ts.map +1 -0
  128. package/dist/test/consts.js +22 -0
  129. package/package.json +11 -20
  130. package/dist/accounts/index.d.ts.map +0 -1
  131. package/dist/accounts/index.js +0 -419
  132. package/dist/accounts/kernel.d.ts.map +0 -1
  133. package/dist/accounts/nexus.d.ts.map +0 -1
  134. package/dist/accounts/safe.d.ts.map +0 -1
  135. package/dist/accounts/utils.d.ts.map +0 -1
  136. package/dist/actions/index.d.ts +0 -29
  137. package/dist/actions/index.d.ts.map +0 -1
  138. package/dist/actions/registry.d.ts +0 -7
  139. package/dist/actions/registry.d.ts.map +0 -1
  140. package/dist/actions/registry.js +0 -7
  141. package/dist/actions/smart-session.d.ts.map +0 -1
  142. package/dist/execution/index.d.ts.map +0 -1
  143. package/dist/execution/index.js +0 -149
  144. package/dist/execution/smart-session.d.ts +0 -23
  145. package/dist/execution/smart-session.d.ts.map +0 -1
  146. package/dist/execution/utils.d.ts +0 -68
  147. package/dist/execution/utils.d.ts.map +0 -1
  148. package/dist/execution/utils.js +0 -482
  149. package/dist/index.d.ts +0 -38
  150. package/dist/index.d.ts.map +0 -1
  151. package/dist/index.js +0 -119
  152. package/dist/modules/abi/smart-sessions.d.ts.map +0 -1
  153. package/dist/modules/common.d.ts.map +0 -1
  154. package/dist/modules/index.d.ts.map +0 -1
  155. package/dist/modules/omni-account.d.ts +0 -9
  156. package/dist/modules/omni-account.d.ts.map +0 -1
  157. package/dist/modules/omni-account.js +0 -15
  158. package/dist/modules/read.d.ts +0 -10
  159. package/dist/modules/read.d.ts.map +0 -1
  160. package/dist/modules/registry.d.ts +0 -9
  161. package/dist/modules/registry.d.ts.map +0 -1
  162. package/dist/modules/registry.js +0 -60
  163. package/dist/modules/validators/core.d.ts.map +0 -1
  164. package/dist/modules/validators/index.d.ts +0 -4
  165. package/dist/modules/validators/index.d.ts.map +0 -1
  166. package/dist/modules/validators/smart-sessions.d.ts.map +0 -1
  167. package/dist/orchestrator/client.d.ts +0 -29
  168. package/dist/orchestrator/client.d.ts.map +0 -1
  169. package/dist/orchestrator/client.js +0 -250
  170. package/dist/orchestrator/consts.d.ts +0 -5
  171. package/dist/orchestrator/consts.d.ts.map +0 -1
  172. package/dist/orchestrator/consts.js +0 -9
  173. package/dist/orchestrator/error.d.ts +0 -18
  174. package/dist/orchestrator/error.d.ts.map +0 -1
  175. package/dist/orchestrator/error.js +0 -33
  176. package/dist/orchestrator/index.d.ts +0 -11
  177. package/dist/orchestrator/index.d.ts.map +0 -1
  178. package/dist/orchestrator/index.js +0 -40
  179. package/dist/orchestrator/registry.d.ts +0 -20
  180. package/dist/orchestrator/registry.d.ts.map +0 -1
  181. package/dist/orchestrator/registry.js +0 -444
  182. package/dist/orchestrator/types.d.ts +0 -242
  183. package/dist/orchestrator/types.d.ts.map +0 -1
  184. package/dist/orchestrator/types.js +0 -19
  185. package/dist/orchestrator/utils.d.ts +0 -29
  186. package/dist/orchestrator/utils.d.ts.map +0 -1
  187. package/dist/orchestrator/utils.js +0 -319
  188. package/dist/types.d.ts.map +0 -1
  189. /package/dist/{actions → src/actions}/smart-session.js +0 -0
  190. /package/dist/{modules → src/modules}/abi/smart-sessions.d.ts +0 -0
  191. /package/dist/{modules → src/modules}/abi/smart-sessions.js +0 -0
  192. /package/dist/{modules → src/modules}/common.d.ts +0 -0
  193. /package/dist/{modules → src/modules}/common.js +0 -0
  194. /package/dist/{types.js → src/types.js} +0 -0
@@ -0,0 +1,105 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.COMPACT_ADDRESS = void 0;
4
+ exports.getDepositEtherCall = getDepositEtherCall;
5
+ exports.getDepositErc20Call = getDepositErc20Call;
6
+ exports.getApproveErc20Call = getApproveErc20Call;
7
+ const viem_1 = require("viem");
8
+ const COMPACT_ADDRESS = '0xa2E6C7Ba8613E1534dCB990e7e4962216C0a5d58';
9
+ exports.COMPACT_ADDRESS = COMPACT_ADDRESS;
10
+ const ALLOCATOR_ADDRESS = '0x9Ef7519F90C9B6828650Ff4913d663BB1f688507';
11
+ const DEFAULT_RESET_PERIOD = 3;
12
+ const DEFAULT_SCOPE = 0;
13
+ function getDepositEtherCall(account, value) {
14
+ return {
15
+ to: COMPACT_ADDRESS,
16
+ data: (0, viem_1.encodeFunctionData)({
17
+ abi: [
18
+ {
19
+ type: 'function',
20
+ name: 'depositNative',
21
+ inputs: [
22
+ { name: 'lockTag', type: 'bytes12', internalType: 'bytes12' },
23
+ { name: 'recipient', type: 'address', internalType: 'address' },
24
+ ],
25
+ outputs: [{ name: '', type: 'uint256', internalType: 'uint256' }],
26
+ stateMutability: 'payable',
27
+ },
28
+ ],
29
+ functionName: 'depositNative',
30
+ args: [lockTag(), account],
31
+ }),
32
+ value,
33
+ };
34
+ }
35
+ function getDepositErc20Call(account, tokenAddress, amount) {
36
+ return {
37
+ to: COMPACT_ADDRESS,
38
+ value: 0n,
39
+ data: (0, viem_1.encodeFunctionData)({
40
+ abi: [
41
+ {
42
+ type: 'function',
43
+ name: 'depositERC20',
44
+ inputs: [
45
+ {
46
+ name: 'token',
47
+ type: 'address',
48
+ internalType: 'address',
49
+ },
50
+ { name: 'lockTag', type: 'bytes12', internalType: 'bytes12' },
51
+ { name: 'amount', type: 'uint256', internalType: 'uint256' },
52
+ { name: 'recipient', type: 'address', internalType: 'address' },
53
+ ],
54
+ outputs: [{ name: 'id', type: 'uint256', internalType: 'uint256' }],
55
+ stateMutability: 'nonpayable',
56
+ },
57
+ ],
58
+ functionName: 'depositERC20',
59
+ args: [tokenAddress, lockTag(), amount, account],
60
+ }),
61
+ };
62
+ }
63
+ function getApproveErc20Call(tokenAddress, amount) {
64
+ return {
65
+ to: tokenAddress,
66
+ value: 0n,
67
+ data: (0, viem_1.encodeFunctionData)({
68
+ abi: viem_1.erc20Abi,
69
+ functionName: 'approve',
70
+ args: [COMPACT_ADDRESS, amount],
71
+ }),
72
+ };
73
+ }
74
+ function toCompactFlag(allocator) {
75
+ const addrBytes = Buffer.from(allocator.slice(2), 'hex');
76
+ let leadingZeroNibbles = 0;
77
+ for (const byte of addrBytes) {
78
+ if (byte === 0) {
79
+ leadingZeroNibbles += 2;
80
+ }
81
+ else {
82
+ if (byte >> 4 === 0)
83
+ leadingZeroNibbles += 1;
84
+ break;
85
+ }
86
+ }
87
+ if (leadingZeroNibbles >= 18)
88
+ return 15;
89
+ if (leadingZeroNibbles >= 4)
90
+ return leadingZeroNibbles - 3;
91
+ return 0;
92
+ }
93
+ function usingAllocatorId(allocator = ALLOCATOR_ADDRESS) {
94
+ const compactFlag = BigInt(toCompactFlag(allocator));
95
+ const last88Bits = BigInt(`0x${allocator.slice(-22)}`); // Extract last 88 bits (11 bytes * 2 hex chars per byte)
96
+ return (compactFlag << 88n) | last88Bits;
97
+ }
98
+ function lockTag() {
99
+ const allocatorId = usingAllocatorId(ALLOCATOR_ADDRESS);
100
+ const tagBig = (BigInt(DEFAULT_SCOPE) << 255n) |
101
+ (BigInt(DEFAULT_RESET_PERIOD) << 252n) |
102
+ (allocatorId << 160n);
103
+ const hex = tagBig.toString(16).slice(0, 24);
104
+ return `0x${hex}`;
105
+ }
@@ -0,0 +1,54 @@
1
+ declare class ExecutionError extends Error {
2
+ private readonly _message;
3
+ private readonly _context;
4
+ private readonly _errorType;
5
+ private readonly _traceId;
6
+ constructor(params?: {
7
+ message?: string;
8
+ context?: any;
9
+ errorType?: string;
10
+ traceId?: string;
11
+ });
12
+ get message(): string;
13
+ get context(): any;
14
+ get errorType(): string;
15
+ get traceId(): string;
16
+ }
17
+ declare class SourceChainsNotAvailableForUserOpFlowError extends ExecutionError {
18
+ constructor(params?: {
19
+ context?: any;
20
+ errorType?: string;
21
+ traceId?: string;
22
+ });
23
+ }
24
+ declare class UserOperationRequiredForSmartSessionsError extends ExecutionError {
25
+ constructor(params?: {
26
+ context?: any;
27
+ errorType?: string;
28
+ traceId?: string;
29
+ });
30
+ }
31
+ declare class OrderPathRequiredForIntentsError extends ExecutionError {
32
+ constructor(params?: {
33
+ context?: any;
34
+ errorType?: string;
35
+ traceId?: string;
36
+ });
37
+ }
38
+ declare class SessionChainRequiredError extends ExecutionError {
39
+ constructor(params?: {
40
+ context?: any;
41
+ errorType?: string;
42
+ traceId?: string;
43
+ });
44
+ }
45
+ declare class IntentFailedError extends ExecutionError {
46
+ constructor(params?: {
47
+ context?: any;
48
+ errorType?: string;
49
+ traceId?: string;
50
+ });
51
+ }
52
+ declare function isExecutionError(error: Error): error is ExecutionError;
53
+ export { isExecutionError, ExecutionError, SourceChainsNotAvailableForUserOpFlowError, UserOperationRequiredForSmartSessionsError, OrderPathRequiredForIntentsError, SessionChainRequiredError, IntentFailedError, };
54
+ //# sourceMappingURL=error.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"error.d.ts","sourceRoot":"","sources":["../../../execution/error.ts"],"names":[],"mappings":"AAAA,cAAM,cAAe,SAAQ,KAAK;IAChC,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAQ;IACjC,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAK;IAC9B,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAQ;IACnC,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAQ;gBAErB,MAAM,CAAC,EAAE;QACnB,OAAO,CAAC,EAAE,MAAM,CAAA;QAChB,OAAO,CAAC,EAAE,GAAG,CAAA;QACb,SAAS,CAAC,EAAE,MAAM,CAAA;QAClB,OAAO,CAAC,EAAE,MAAM,CAAA;KACjB;IAQD,IAAI,OAAO,WAEV;IAED,IAAI,OAAO,QAEV;IAED,IAAI,SAAS,WAEZ;IAED,IAAI,OAAO,WAEV;CACF;AAED,cAAM,0CAA2C,SAAQ,cAAc;gBACzD,MAAM,CAAC,EAAE;QACnB,OAAO,CAAC,EAAE,GAAG,CAAA;QACb,SAAS,CAAC,EAAE,MAAM,CAAA;QAClB,OAAO,CAAC,EAAE,MAAM,CAAA;KACjB;CAMF;AAED,cAAM,0CAA2C,SAAQ,cAAc;gBACzD,MAAM,CAAC,EAAE;QACnB,OAAO,CAAC,EAAE,GAAG,CAAA;QACb,SAAS,CAAC,EAAE,MAAM,CAAA;QAClB,OAAO,CAAC,EAAE,MAAM,CAAA;KACjB;CAMF;AAED,cAAM,gCAAiC,SAAQ,cAAc;gBAC/C,MAAM,CAAC,EAAE;QACnB,OAAO,CAAC,EAAE,GAAG,CAAA;QACb,SAAS,CAAC,EAAE,MAAM,CAAA;QAClB,OAAO,CAAC,EAAE,MAAM,CAAA;KACjB;CAMF;AAED,cAAM,yBAA0B,SAAQ,cAAc;gBACxC,MAAM,CAAC,EAAE;QACnB,OAAO,CAAC,EAAE,GAAG,CAAA;QACb,SAAS,CAAC,EAAE,MAAM,CAAA;QAClB,OAAO,CAAC,EAAE,MAAM,CAAA;KACjB;CAOF;AAED,cAAM,iBAAkB,SAAQ,cAAc;gBAChC,MAAM,CAAC,EAAE;QACnB,OAAO,CAAC,EAAE,GAAG,CAAA;QACb,SAAS,CAAC,EAAE,MAAM,CAAA;QAClB,OAAO,CAAC,EAAE,MAAM,CAAA;KACjB;CAMF;AAED,iBAAS,gBAAgB,CAAC,KAAK,EAAE,KAAK,GAAG,KAAK,IAAI,cAAc,CAE/D;AAED,OAAO,EACL,gBAAgB,EAChB,cAAc,EACd,0CAA0C,EAC1C,0CAA0C,EAC1C,gCAAgC,EAChC,yBAAyB,EACzB,iBAAiB,GAClB,CAAA"}
@@ -0,0 +1,78 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.IntentFailedError = exports.SessionChainRequiredError = exports.OrderPathRequiredForIntentsError = exports.UserOperationRequiredForSmartSessionsError = exports.SourceChainsNotAvailableForUserOpFlowError = exports.ExecutionError = void 0;
4
+ exports.isExecutionError = isExecutionError;
5
+ class ExecutionError extends Error {
6
+ _message;
7
+ _context;
8
+ _errorType;
9
+ _traceId;
10
+ constructor(params) {
11
+ super();
12
+ this._message = params?.message || 'ExecutionError';
13
+ this._context = params?.context || {};
14
+ this._errorType = params?.errorType || 'Unknown';
15
+ this._traceId = params?.traceId || '';
16
+ }
17
+ get message() {
18
+ return this._message;
19
+ }
20
+ get context() {
21
+ return this._context;
22
+ }
23
+ get errorType() {
24
+ return this._errorType;
25
+ }
26
+ get traceId() {
27
+ return this._traceId;
28
+ }
29
+ }
30
+ exports.ExecutionError = ExecutionError;
31
+ class SourceChainsNotAvailableForUserOpFlowError extends ExecutionError {
32
+ constructor(params) {
33
+ super({
34
+ message: "Can't specify the source chains when using user operations",
35
+ ...params,
36
+ });
37
+ }
38
+ }
39
+ exports.SourceChainsNotAvailableForUserOpFlowError = SourceChainsNotAvailableForUserOpFlowError;
40
+ class UserOperationRequiredForSmartSessionsError extends ExecutionError {
41
+ constructor(params) {
42
+ super({
43
+ message: 'User operation is required when using smart sessions',
44
+ ...params,
45
+ });
46
+ }
47
+ }
48
+ exports.UserOperationRequiredForSmartSessionsError = UserOperationRequiredForSmartSessionsError;
49
+ class OrderPathRequiredForIntentsError extends ExecutionError {
50
+ constructor(params) {
51
+ super({
52
+ message: 'Order path is required when using intents',
53
+ ...params,
54
+ });
55
+ }
56
+ }
57
+ exports.OrderPathRequiredForIntentsError = OrderPathRequiredForIntentsError;
58
+ class SessionChainRequiredError extends ExecutionError {
59
+ constructor(params) {
60
+ super({
61
+ message: 'Specifying a chain is required when using multi-chain smart sessions',
62
+ ...params,
63
+ });
64
+ }
65
+ }
66
+ exports.SessionChainRequiredError = SessionChainRequiredError;
67
+ class IntentFailedError extends ExecutionError {
68
+ constructor(params) {
69
+ super({
70
+ message: 'Intent failed',
71
+ ...params,
72
+ });
73
+ }
74
+ }
75
+ exports.IntentFailedError = IntentFailedError;
76
+ function isExecutionError(error) {
77
+ return error instanceof ExecutionError;
78
+ }
@@ -1,9 +1,10 @@
1
1
  import { type Address, type Chain } from 'viem';
2
- import type { BundleResult } from '../orchestrator';
2
+ import type { IntentOpStatus } from '../orchestrator';
3
3
  import type { RhinestoneAccountConfig, Transaction } from '../types';
4
- import type { BundleData, TransactionResult } from './utils';
4
+ import { ExecutionError, IntentFailedError, isExecutionError, OrderPathRequiredForIntentsError, SessionChainRequiredError, SourceChainsNotAvailableForUserOpFlowError, UserOperationRequiredForSmartSessionsError } from './error';
5
+ import type { IntentData, TransactionResult } from './utils';
5
6
  declare function sendTransaction(config: RhinestoneAccountConfig, transaction: Transaction): Promise<TransactionResult>;
6
- declare function waitForExecution(config: RhinestoneAccountConfig, result: TransactionResult, acceptsPreconfirmations: boolean): Promise<BundleResult | {
7
+ declare function waitForExecution(config: RhinestoneAccountConfig, result: TransactionResult, acceptsPreconfirmations: boolean): Promise<IntentOpStatus | {
7
8
  actualGasCost: bigint;
8
9
  actualGasUsed: bigint;
9
10
  entryPoint: Address;
@@ -17,7 +18,7 @@ declare function waitForExecution(config: RhinestoneAccountConfig, result: Trans
17
18
  userOpHash: import("viem").Hash;
18
19
  }>;
19
20
  declare function getMaxSpendableAmount(config: RhinestoneAccountConfig, chain: Chain, tokenAddress: Address, gasUnits: bigint): Promise<bigint>;
20
- declare function getPortfolio(config: RhinestoneAccountConfig, onTestnets: boolean): Promise<import("../orchestrator").UserTokenBalance[]>;
21
- export { sendTransaction, waitForExecution, getMaxSpendableAmount, getPortfolio, };
22
- export type { BundleData, TransactionResult };
21
+ declare function getPortfolio(config: RhinestoneAccountConfig, onTestnets: boolean): Promise<import("../orchestrator").Portfolio>;
22
+ export { sendTransaction, waitForExecution, getMaxSpendableAmount, getPortfolio, isExecutionError, IntentFailedError, ExecutionError, SourceChainsNotAvailableForUserOpFlowError, UserOperationRequiredForSmartSessionsError, OrderPathRequiredForIntentsError, SessionChainRequiredError, };
23
+ export type { IntentData, TransactionResult };
23
24
  //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../execution/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,OAAO,EAAE,KAAK,KAAK,EAAmC,MAAM,MAAM,CAAA;AAKhF,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAA;AAQrD,OAAO,KAAK,EAEV,uBAAuB,EAGvB,WAAW,EACZ,MAAM,UAAU,CAAA;AACjB,OAAO,EACL,cAAc,EACd,iBAAiB,EACjB,gBAAgB,EAChB,gCAAgC,EAChC,yBAAyB,EACzB,0CAA0C,EAC1C,0CAA0C,EAC3C,MAAM,SAAS,CAAA;AAEhB,OAAO,KAAK,EAAE,UAAU,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAA;AAa5D,iBAAe,eAAe,CAC5B,MAAM,EAAE,uBAAuB,EAC/B,WAAW,EAAE,WAAW,8BA2BzB;AAqID,iBAAe,gBAAgB,CAC7B,MAAM,EAAE,uBAAuB,EAC/B,MAAM,EAAE,iBAAiB,EACzB,uBAAuB,EAAE,OAAO;;;;;;;;;;;;GA2CjC;AAED,iBAAe,qBAAqB,CAClC,MAAM,EAAE,uBAAuB,EAC/B,KAAK,EAAE,KAAK,EACZ,YAAY,EAAE,OAAO,EACrB,QAAQ,EAAE,MAAM,GACf,OAAO,CAAC,MAAM,CAAC,CASjB;AAED,iBAAe,YAAY,CACzB,MAAM,EAAE,uBAAuB,EAC/B,UAAU,EAAE,OAAO,gDAMpB;AAED,OAAO,EACL,eAAe,EACf,gBAAgB,EAChB,qBAAqB,EACrB,YAAY,EAEZ,gBAAgB,EAChB,iBAAiB,EACjB,cAAc,EACd,0CAA0C,EAC1C,0CAA0C,EAC1C,gCAAgC,EAChC,yBAAyB,GAC1B,CAAA;AACD,YAAY,EAAE,UAAU,EAAE,iBAAiB,EAAE,CAAA"}
@@ -0,0 +1,150 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SessionChainRequiredError = exports.OrderPathRequiredForIntentsError = exports.UserOperationRequiredForSmartSessionsError = exports.SourceChainsNotAvailableForUserOpFlowError = exports.ExecutionError = exports.IntentFailedError = exports.isExecutionError = void 0;
4
+ exports.sendTransaction = sendTransaction;
5
+ exports.waitForExecution = waitForExecution;
6
+ exports.getMaxSpendableAmount = getMaxSpendableAmount;
7
+ exports.getPortfolio = getPortfolio;
8
+ const viem_1 = require("viem");
9
+ const chains_1 = require("viem/chains");
10
+ const accounts_1 = require("../accounts");
11
+ const utils_1 = require("../accounts/utils");
12
+ const orchestrator_1 = require("../orchestrator");
13
+ const registry_1 = require("../orchestrator/registry");
14
+ const error_1 = require("./error");
15
+ Object.defineProperty(exports, "ExecutionError", { enumerable: true, get: function () { return error_1.ExecutionError; } });
16
+ Object.defineProperty(exports, "IntentFailedError", { enumerable: true, get: function () { return error_1.IntentFailedError; } });
17
+ Object.defineProperty(exports, "isExecutionError", { enumerable: true, get: function () { return error_1.isExecutionError; } });
18
+ Object.defineProperty(exports, "OrderPathRequiredForIntentsError", { enumerable: true, get: function () { return error_1.OrderPathRequiredForIntentsError; } });
19
+ Object.defineProperty(exports, "SessionChainRequiredError", { enumerable: true, get: function () { return error_1.SessionChainRequiredError; } });
20
+ Object.defineProperty(exports, "SourceChainsNotAvailableForUserOpFlowError", { enumerable: true, get: function () { return error_1.SourceChainsNotAvailableForUserOpFlowError; } });
21
+ Object.defineProperty(exports, "UserOperationRequiredForSmartSessionsError", { enumerable: true, get: function () { return error_1.UserOperationRequiredForSmartSessionsError; } });
22
+ const smart_session_1 = require("./smart-session");
23
+ const utils_2 = require("./utils");
24
+ const POLLING_INTERVAL = 500;
25
+ async function sendTransaction(config, transaction) {
26
+ if ('chain' in transaction) {
27
+ // Same-chain transaction
28
+ return await sendTransactionInternal(config, [transaction.chain], transaction.chain, transaction.calls, transaction.gasLimit, transaction.tokenRequests, transaction.signers, transaction.sponsored);
29
+ }
30
+ else {
31
+ // Cross-chain transaction
32
+ return await sendTransactionInternal(config, transaction.sourceChains || [], transaction.targetChain, transaction.calls, transaction.gasLimit, transaction.tokenRequests, transaction.signers, transaction.sponsored);
33
+ }
34
+ }
35
+ async function sendTransactionInternal(config, sourceChains, targetChain, callInputs, gasLimit, initialTokenRequests, signers, sponsored) {
36
+ const accountAddress = (0, accounts_1.getAddress)(config);
37
+ // Across requires passing some value to repay the solvers
38
+ const tokenRequests = !initialTokenRequests || initialTokenRequests.length === 0
39
+ ? [
40
+ {
41
+ address: viem_1.zeroAddress,
42
+ amount: 1n,
43
+ },
44
+ ]
45
+ : initialTokenRequests;
46
+ const asUserOp = signers?.type === 'guardians' || signers?.type === 'session';
47
+ if (asUserOp) {
48
+ const withSession = signers?.type === 'session' ? signers.session : null;
49
+ if (withSession) {
50
+ await (0, smart_session_1.enableSmartSession)(targetChain, config, withSession);
51
+ }
52
+ // Smart sessions require a UserOp flow
53
+ return await sendTransactionAsUserOp(config, targetChain, callInputs, signers);
54
+ }
55
+ else {
56
+ return await sendTransactionAsIntent(config, sourceChains, targetChain, callInputs, gasLimit, tokenRequests, accountAddress, signers, sponsored);
57
+ }
58
+ }
59
+ async function sendTransactionAsUserOp(config, chain, callInputs, signers) {
60
+ // Make sure the account is deployed
61
+ await (0, accounts_1.deploy)(config, chain);
62
+ const withSession = signers?.type === 'session' ? signers.session : null;
63
+ const publicClient = (0, viem_1.createPublicClient)({
64
+ chain,
65
+ transport: (0, utils_1.createTransport)(chain, config.provider),
66
+ });
67
+ const validatorAccount = await (0, utils_2.getValidatorAccount)(config, signers, publicClient, chain);
68
+ if (!validatorAccount) {
69
+ throw new Error('No validator account found');
70
+ }
71
+ const bundlerClient = (0, utils_1.getBundlerClient)(config, publicClient);
72
+ if (withSession) {
73
+ await (0, smart_session_1.enableSmartSession)(chain, config, withSession);
74
+ }
75
+ const calls = (0, utils_2.parseCalls)(callInputs, chain.id);
76
+ const hash = await bundlerClient.sendUserOperation({
77
+ account: validatorAccount,
78
+ calls,
79
+ });
80
+ return {
81
+ type: 'userop',
82
+ hash,
83
+ chain: chain.id,
84
+ };
85
+ }
86
+ async function sendTransactionAsIntent(config, sourceChains, targetChain, callInputs, gasLimit, tokenRequests, accountAddress, signers, sponsored) {
87
+ const { intentRoute, hash: intentHash } = await (0, utils_2.prepareTransactionAsIntent)(config, sourceChains, targetChain, callInputs, gasLimit, tokenRequests, accountAddress, sponsored ?? false);
88
+ if (!intentRoute) {
89
+ throw new error_1.OrderPathRequiredForIntentsError();
90
+ }
91
+ const signature = await (0, utils_2.signIntent)(config, targetChain, intentHash, signers);
92
+ const authorizations = config.eoa
93
+ ? await (0, utils_2.signAuthorizationsInternal)(config, {
94
+ type: 'intent',
95
+ intentRoute,
96
+ hash: intentHash,
97
+ })
98
+ : [];
99
+ return await (0, utils_2.submitIntentInternal)(config, sourceChains, targetChain, intentRoute.intentOp, signature, authorizations);
100
+ }
101
+ async function waitForExecution(config, result, acceptsPreconfirmations) {
102
+ const validStatuses = new Set([
103
+ orchestrator_1.INTENT_STATUS_FAILED,
104
+ orchestrator_1.INTENT_STATUS_COMPLETED,
105
+ orchestrator_1.INTENT_STATUS_FILLED,
106
+ ]);
107
+ if (acceptsPreconfirmations) {
108
+ validStatuses.add(orchestrator_1.INTENT_STATUS_PRECONFIRMED);
109
+ }
110
+ switch (result.type) {
111
+ case 'intent': {
112
+ let intentStatus = null;
113
+ while (intentStatus === null || !validStatuses.has(intentStatus.status)) {
114
+ const orchestrator = (0, utils_2.getOrchestratorByChain)(result.targetChain, config.rhinestoneApiKey);
115
+ intentStatus = await orchestrator.getIntentOpStatus(result.id);
116
+ await new Promise((resolve) => setTimeout(resolve, POLLING_INTERVAL));
117
+ }
118
+ if (intentStatus.status === orchestrator_1.INTENT_STATUS_FAILED) {
119
+ throw new error_1.IntentFailedError();
120
+ }
121
+ return intentStatus;
122
+ }
123
+ case 'userop': {
124
+ const targetChain = (0, registry_1.getChainById)(result.chain);
125
+ if (!targetChain) {
126
+ throw new Error(`Unsupported chain ID: ${result.chain}`);
127
+ }
128
+ const publicClient = (0, viem_1.createPublicClient)({
129
+ chain: targetChain,
130
+ transport: (0, utils_1.createTransport)(targetChain, config.provider),
131
+ });
132
+ const bundlerClient = (0, utils_1.getBundlerClient)(config, publicClient);
133
+ const receipt = await bundlerClient.waitForUserOperationReceipt({
134
+ hash: result.hash,
135
+ });
136
+ return receipt;
137
+ }
138
+ }
139
+ }
140
+ async function getMaxSpendableAmount(config, chain, tokenAddress, gasUnits) {
141
+ const address = (0, accounts_1.getAddress)(config);
142
+ const orchestrator = (0, utils_2.getOrchestratorByChain)(chain.id, config.rhinestoneApiKey);
143
+ return orchestrator.getMaxTokenAmount(address, chain.id, tokenAddress, gasUnits);
144
+ }
145
+ async function getPortfolio(config, onTestnets) {
146
+ const address = (0, accounts_1.getAddress)(config);
147
+ const chainId = onTestnets ? chains_1.sepolia.id : chains_1.mainnet.id;
148
+ const orchestrator = (0, utils_2.getOrchestratorByChain)(chainId, config.rhinestoneApiKey);
149
+ return orchestrator.getPortfolio(address);
150
+ }
@@ -0,0 +1,15 @@
1
+ import { type Chain, type Hex } from 'viem';
2
+ import { type ChainDigest, type EnableSessionData, type SmartSessionModeType } from '../modules/validators/smart-sessions';
3
+ import type { RhinestoneAccountConfig, Session } from '../types';
4
+ interface SessionDetails {
5
+ permissionEnableHash: Hex;
6
+ mode: SmartSessionModeType;
7
+ hashesAndChainIds: ChainDigest[];
8
+ enableSessionData: EnableSessionData;
9
+ }
10
+ declare function getSessionDetails(config: RhinestoneAccountConfig, sessions: Session[], sessionIndex: number, signature?: Hex): Promise<SessionDetails>;
11
+ declare function getMultichainDigest(chainDigests: ChainDigest[]): Hex;
12
+ declare function enableSmartSession(chain: Chain, config: RhinestoneAccountConfig, session: Session): Promise<void>;
13
+ export { enableSmartSession, getSessionDetails, getMultichainDigest };
14
+ export type { SessionDetails };
15
+ //# sourceMappingURL=smart-session.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"smart-session.d.ts","sourceRoot":"","sources":["../../../execution/smart-session.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,KAAK,EAIV,KAAK,GAAG,EAGT,MAAM,MAAM,CAAA;AAmBb,OAAO,EACL,KAAK,WAAW,EAEhB,KAAK,iBAAiB,EAGtB,KAAK,oBAAoB,EAC1B,MAAM,sCAAsC,CAAA;AAC7C,OAAO,KAAK,EAGV,uBAAuB,EACvB,OAAO,EACR,MAAM,UAAU,CAAA;AAGjB,UAAU,cAAc;IACtB,oBAAoB,EAAE,GAAG,CAAA;IACzB,IAAI,EAAE,oBAAoB,CAAA;IAC1B,iBAAiB,EAAE,WAAW,EAAE,CAAA;IAChC,iBAAiB,EAAE,iBAAiB,CAAA;CACrC;AAED,iBAAe,iBAAiB,CAC9B,MAAM,EAAE,uBAAuB,EAC/B,QAAQ,EAAE,OAAO,EAAE,EACnB,YAAY,EAAE,MAAM,EACpB,SAAS,CAAC,EAAE,GAAG,GACd,OAAO,CAAC,cAAc,CAAC,CA4BzB;AAgGD,iBAAS,mBAAmB,CAAC,YAAY,EAAE,WAAW,EAAE,GAAG,GAAG,CAgC7D;AAiLD,iBAAe,kBAAkB,CAC/B,KAAK,EAAE,KAAK,EACZ,MAAM,EAAE,uBAAuB,EAC/B,OAAO,EAAE,OAAO,iBA+BjB;AAED,OAAO,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,mBAAmB,EAAE,CAAA;AACrE,YAAY,EAAE,cAAc,EAAE,CAAA"}
@@ -1,24 +1,21 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.enableSmartSession = enableSmartSession;
4
- exports.hashErc7739 = hashErc7739;
5
- exports.getSessionSignature = getSessionSignature;
6
4
  exports.getSessionDetails = getSessionDetails;
7
5
  exports.getMultichainDigest = getMultichainDigest;
8
6
  const viem_1 = require("viem");
9
7
  const accounts_1 = require("../accounts");
10
8
  const utils_1 = require("../accounts/utils");
11
- const modules_1 = require("../modules");
12
9
  const validators_1 = require("../modules/validators");
13
10
  const smart_sessions_1 = require("../modules/validators/smart-sessions");
14
- const utils_2 = require("../orchestrator/utils");
11
+ const error_1 = require("./error");
15
12
  async function getSessionDetails(config, sessions, sessionIndex, signature) {
16
13
  const account = (0, accounts_1.getAccountProvider)(config);
17
14
  const accountAddress = (0, accounts_1.getAddress)(config);
18
- const sessionDetails = await getEnableSessionDetails(account.type, sessions, sessionIndex, accountAddress);
15
+ const sessionDetails = await getEnableSessionDetails(account.type, sessions, sessionIndex, accountAddress, config.provider);
19
16
  const chain = sessions[sessionIndex].chain;
20
17
  if (!chain) {
21
- throw new Error('Session chain is required');
18
+ throw new error_1.SessionChainRequiredError();
22
19
  }
23
20
  const validator = {
24
21
  address: sessionDetails.enableSessionData.validator,
@@ -26,24 +23,24 @@ async function getSessionDetails(config, sessions, sessionIndex, signature) {
26
23
  };
27
24
  sessionDetails.enableSessionData.signature =
28
25
  signature ??
29
- (await (0, accounts_1.getPackedSignature)(config, config.owners, chain, validator, sessionDetails.permissionEnableHash));
26
+ (await (0, accounts_1.getPackedSignature)(config, undefined, chain, validator, sessionDetails.permissionEnableHash));
30
27
  return sessionDetails;
31
28
  }
32
- async function getEnableSessionDetails(accountType, sessions, sessionIndex, accountAddress) {
29
+ async function getEnableSessionDetails(accountType, sessions, sessionIndex, accountAddress, provider) {
33
30
  const chainDigests = [];
34
31
  const chainSessions = [];
35
32
  for (const session of sessions) {
36
33
  const permissionId = (0, validators_1.getPermissionId)(session);
37
- const publicClient = (0, viem_1.createPublicClient)({
38
- chain: session.chain,
39
- transport: (0, viem_1.http)(),
40
- });
41
34
  const sessionChain = session.chain;
42
35
  if (!sessionChain) {
43
- throw new Error('Session chain is required');
36
+ throw new error_1.SessionChainRequiredError();
44
37
  }
38
+ const publicClient = (0, viem_1.createPublicClient)({
39
+ chain: sessionChain,
40
+ transport: (0, utils_1.createTransport)(sessionChain, provider),
41
+ });
45
42
  const sessionNonce = await getSessionNonce(publicClient, accountAddress, permissionId);
46
- const sessionData = await (0, smart_sessions_1.getSessionData)(sessionChain, session);
43
+ const sessionData = await (0, smart_sessions_1.getSessionData)(sessionChain, session, provider);
47
44
  const sessionDigest = await getSessionDigest(publicClient, accountAddress, sessionData, permissionId, validators_1.SMART_SESSION_MODE_ENABLE);
48
45
  chainDigests.push({
49
46
  chainId: BigInt(sessionChain.id),
@@ -74,9 +71,9 @@ async function getEnableSessionDetails(accountType, sessions, sessionIndex, acco
74
71
  const sessionToEnable = sessions[sessionIndex || 0];
75
72
  const sessionChain = sessionToEnable.chain;
76
73
  if (!sessionChain) {
77
- throw new Error('Session chain is required');
74
+ throw new error_1.SessionChainRequiredError();
78
75
  }
79
- const sessionData = await (0, smart_sessions_1.getSessionData)(sessionChain, sessionToEnable);
76
+ const sessionData = await (0, smart_sessions_1.getSessionData)(sessionChain, sessionToEnable, provider);
80
77
  return {
81
78
  permissionEnableHash,
82
79
  mode: validators_1.SMART_SESSION_MODE_ENABLE,
@@ -276,79 +273,21 @@ async function getSessionDigest(client, account, session, permissionId, mode) {
276
273
  async function enableSmartSession(chain, config, session) {
277
274
  const publicClient = (0, viem_1.createPublicClient)({
278
275
  chain,
279
- transport: (0, viem_1.http)(),
276
+ transport: (0, utils_1.createTransport)(chain, config.provider),
280
277
  });
281
278
  const address = (0, accounts_1.getAddress)(config);
282
279
  const isEnabled = await (0, validators_1.isSessionEnabled)(publicClient, address, (0, validators_1.getPermissionId)(session));
283
280
  if (isEnabled) {
284
281
  return;
285
282
  }
286
- const enableSessionCall = await (0, validators_1.getEnableSessionCall)(chain, session);
287
- const trustedAttesters = await (0, modules_1.getTrustedAttesters)(publicClient, address);
288
- const trustAttesterCall = trustedAttesters.length === 0 ? (0, modules_1.getTrustAttesterCall)(config) : undefined;
283
+ const enableSessionCall = await (0, validators_1.getEnableSessionCall)(chain, session, config.provider);
289
284
  const smartAccount = await (0, accounts_1.getSmartAccount)(config, publicClient, chain);
290
285
  const bundlerClient = (0, utils_1.getBundlerClient)(config, publicClient);
291
286
  const opHash = await bundlerClient.sendUserOperation({
292
287
  account: smartAccount,
293
- calls: trustAttesterCall
294
- ? [trustAttesterCall, enableSessionCall]
295
- : [enableSessionCall],
288
+ calls: [enableSessionCall],
296
289
  });
297
290
  await bundlerClient.waitForUserOperationReceipt({
298
291
  hash: opHash,
299
292
  });
300
293
  }
301
- async function hashErc7739(sourceChain, orderPath, accountAddress) {
302
- const publicClient = (0, viem_1.createPublicClient)({
303
- chain: sourceChain,
304
- transport: (0, viem_1.http)(),
305
- });
306
- const { appDomainSeparator, contentsType } = await (0, validators_1.getSessionAllowedERC7739Content)(sourceChain);
307
- // Create hash following ERC-7739 TypedDataSign workflow
308
- const typedDataSignTypehash = (0, viem_1.keccak256)((0, viem_1.encodePacked)(['string'], [
309
- 'TypedDataSign(MultichainCompact contents,string name,string version,uint256 chainId,address verifyingContract,bytes32 salt)'.concat(contentsType),
310
- ]));
311
- // Original struct hash
312
- const structHash = (0, utils_2.hashMultichainCompactWithoutDomainSeparator)(orderPath[0].orderBundle);
313
- const { name, version, chainId, verifyingContract, salt } = await (0, validators_1.getAccountEIP712Domain)(publicClient, accountAddress);
314
- // Final hash according to ERC-7739
315
- const hash = (0, viem_1.keccak256)((0, viem_1.encodePacked)(['bytes2', 'bytes32', 'bytes32'], [
316
- '0x1901',
317
- appDomainSeparator,
318
- (0, viem_1.keccak256)((0, viem_1.encodeAbiParameters)([
319
- { name: 'typedDataSignTypehash', type: 'bytes32' },
320
- { name: 'structHash', type: 'bytes32' },
321
- { name: 'name', type: 'bytes32' },
322
- { name: 'version', type: 'bytes32' },
323
- { name: 'chainId', type: 'uint256' },
324
- { name: 'verifyingContract', type: 'address' },
325
- { name: 'salt', type: 'bytes32' },
326
- ], [
327
- typedDataSignTypehash,
328
- structHash,
329
- (0, viem_1.keccak256)((0, viem_1.encodePacked)(['string'], [name])),
330
- (0, viem_1.keccak256)((0, viem_1.encodePacked)(['string'], [version])),
331
- BigInt(Number(chainId)),
332
- verifyingContract,
333
- salt,
334
- ])),
335
- ]));
336
- return {
337
- hash,
338
- appDomainSeparator,
339
- contentsType,
340
- structHash,
341
- };
342
- }
343
- function getSessionSignature(signature, appDomainSeparator, structHash, contentsType, withSession) {
344
- const erc7739Signature = (0, viem_1.encodePacked)(['bytes', 'bytes32', 'bytes32', 'string', 'uint16'], [
345
- signature,
346
- appDomainSeparator,
347
- structHash,
348
- contentsType,
349
- contentsType.length,
350
- ]);
351
- // Pack with permissionId for smart session
352
- const wrappedSignature = (0, viem_1.encodePacked)(['bytes32', 'bytes'], [(0, validators_1.getPermissionId)(withSession), erc7739Signature]);
353
- return wrappedSignature;
354
- }
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=smart-session.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"smart-session.test.d.ts","sourceRoot":"","sources":["../../../execution/smart-session.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const vitest_1 = require("vitest");
4
+ const smart_session_1 = require("./smart-session");
5
+ (0, vitest_1.describe)('Smart Session', () => {
6
+ (0, vitest_1.describe)('Multichain Digest', () => {
7
+ (0, vitest_1.test)('Single', () => {
8
+ const digest = (0, smart_session_1.getMultichainDigest)([
9
+ {
10
+ chainId: 421614n,
11
+ sessionDigest: '0x971daa09e9deb42457fb008fce5a63987379b31fd67ec6c16ff8b52517bfb373',
12
+ },
13
+ ]);
14
+ (0, vitest_1.expect)(digest).toEqual('0xc0f5a263b2af5a01bc221835faf49b77459a5696f881c25fea9f8144c43f2326');
15
+ });
16
+ (0, vitest_1.test)('Multiple', () => {
17
+ const digest = (0, smart_session_1.getMultichainDigest)([
18
+ {
19
+ chainId: 84532n,
20
+ sessionDigest: '0xad3139c2b3ca57ba02e86ba3ad86dd18a05ba53650e3088ebd4fed71166d4bdd',
21
+ },
22
+ {
23
+ chainId: 84532n,
24
+ sessionDigest: '0x1e6cc59dee4aca4a0d9b1fccd6fde197c831d5bd51163746f1947b352732f3db',
25
+ },
26
+ {
27
+ chainId: 11155420n,
28
+ sessionDigest: '0x9b14ad37022e97faf4d9824c8d7e85b97f304839d24a3cd582575753df7d9239',
29
+ },
30
+ ]);
31
+ (0, vitest_1.expect)(digest).toEqual('0x02f738c7e916839b958b21cbf8bf3697ca06fcb7d5fd5eba85ad49c8f2756adb');
32
+ });
33
+ });
34
+ });