@metamask/smart-accounts-kit 0.2.0 → 0.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.
- package/CHANGELOG.md +9 -1
- package/dist/actions/index.cjs +5 -5
- package/dist/actions/index.mjs +4 -4
- package/dist/{chunk-K5C42JZ2.mjs → chunk-2HNEALPY.mjs} +4 -4
- package/dist/{chunk-PSERHFRY.mjs → chunk-3JBYBEYP.mjs} +2 -2
- package/dist/{chunk-PZM5E7L3.cjs → chunk-4QBJFYZ7.cjs} +12 -12
- package/dist/{chunk-PZM5E7L3.cjs.map → chunk-4QBJFYZ7.cjs.map} +1 -1
- package/dist/{chunk-AAYEHQXN.cjs → chunk-5ZBCTLQS.cjs} +8 -8
- package/dist/{chunk-AAYEHQXN.cjs.map → chunk-5ZBCTLQS.cjs.map} +1 -1
- package/dist/{chunk-DR5QAW34.mjs → chunk-72UQFUL5.mjs} +2 -2
- package/dist/{chunk-Q6ZTEHYY.mjs → chunk-BJGZGTRU.mjs} +3 -2
- package/dist/{chunk-Q6ZTEHYY.mjs.map → chunk-BJGZGTRU.mjs.map} +1 -1
- package/dist/{chunk-CE3ZQE3P.cjs → chunk-BWR5ZK6Z.cjs} +3 -3
- package/dist/{chunk-CE3ZQE3P.cjs.map → chunk-BWR5ZK6Z.cjs.map} +1 -1
- package/dist/{chunk-4WKZQUP4.cjs → chunk-DLR4BZKP.cjs} +102 -102
- package/dist/{chunk-4WKZQUP4.cjs.map → chunk-DLR4BZKP.cjs.map} +1 -1
- package/dist/{chunk-LCNP5VYR.mjs → chunk-F5U55BIP.mjs} +2 -2
- package/dist/{chunk-MAPUND7S.cjs → chunk-HJETDDBN.cjs} +3 -2
- package/dist/chunk-HJETDDBN.cjs.map +1 -0
- package/dist/{chunk-3OQKCVQC.mjs → chunk-KTAXE6PZ.mjs} +4 -4
- package/dist/{chunk-XU72WGZA.cjs → chunk-QHDMZSGQ.cjs} +11 -11
- package/dist/{chunk-XU72WGZA.cjs.map → chunk-QHDMZSGQ.cjs.map} +1 -1
- package/dist/{chunk-PTIEXLLP.cjs → chunk-QPCM4XRT.cjs} +18 -18
- package/dist/{chunk-PTIEXLLP.cjs.map → chunk-QPCM4XRT.cjs.map} +1 -1
- package/dist/{chunk-XHKSMZ7G.mjs → chunk-Y5MOTV4T.mjs} +2 -2
- package/dist/contracts/index.cjs +5 -5
- package/dist/contracts/index.d.cts +2 -2
- package/dist/contracts/index.d.ts +2 -2
- package/dist/contracts/index.mjs +4 -4
- package/dist/{delegation-d52Owevd.d.cts → delegation-C7M1fy5Q.d.cts} +2 -2
- package/dist/{delegation-7PtFix8Y.d.ts → delegation-CCMAKs7W.d.ts} +2 -2
- package/dist/experimental/index.cjs +3 -3
- package/dist/experimental/index.mjs +1 -1
- package/dist/{index-0-B0YlEP.d.cts → index-BGXTbonF.d.cts} +1 -1
- package/dist/{index-D1WbhKCc.d.ts → index-DeHcI5-n.d.ts} +1 -1
- package/dist/index.cjs +19 -19
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.mjs +7 -7
- package/dist/utils/index.cjs +5 -5
- package/dist/utils/index.d.cts +1 -1
- package/dist/utils/index.d.ts +1 -1
- package/dist/utils/index.mjs +4 -4
- package/package.json +17 -1
- package/dist/chunk-MAPUND7S.cjs.map +0 -1
- /package/dist/{chunk-K5C42JZ2.mjs.map → chunk-2HNEALPY.mjs.map} +0 -0
- /package/dist/{chunk-PSERHFRY.mjs.map → chunk-3JBYBEYP.mjs.map} +0 -0
- /package/dist/{chunk-DR5QAW34.mjs.map → chunk-72UQFUL5.mjs.map} +0 -0
- /package/dist/{chunk-LCNP5VYR.mjs.map → chunk-F5U55BIP.mjs.map} +0 -0
- /package/dist/{chunk-3OQKCVQC.mjs.map → chunk-KTAXE6PZ.mjs.map} +0 -0
- /package/dist/{chunk-XHKSMZ7G.mjs.map → chunk-Y5MOTV4T.mjs.map} +0 -0
package/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
## [0.3.0]
|
|
11
|
+
|
|
12
|
+
### Fixed
|
|
13
|
+
|
|
14
|
+
- **Breaking** `function-call` scope no longer allows native token value, unless explicitly configured ([#118](https://github.com/MetaMask/smart-accounts-kit/pull/118))
|
|
15
|
+
- Add `typesVersions` to `package.json` so that subpath exports can be resolved for packages using `moduleResolution: node` ([#112](https://github.com/MetaMask/smart-accounts-kit/pull/112))
|
|
16
|
+
|
|
10
17
|
## [0.2.0]
|
|
11
18
|
|
|
12
19
|
### Added
|
|
@@ -23,6 +30,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
23
30
|
|
|
24
31
|
- Promote readable permissions actions (`requestExecutionPermissions`, `sendTransactionWithDelegation`, and `sendUserOperationWithDelegation`) from experimental ([#91](https://github.com/MetaMask/smart-accounts-kit/pull/91))
|
|
25
32
|
|
|
26
|
-
[Unreleased]: https://github.com/metamask/smart-accounts-kit/compare/@metamask/smart-accounts-kit@0.
|
|
33
|
+
[Unreleased]: https://github.com/metamask/smart-accounts-kit/compare/@metamask/smart-accounts-kit@0.3.0...HEAD
|
|
34
|
+
[0.3.0]: https://github.com/metamask/smart-accounts-kit/compare/@metamask/smart-accounts-kit@0.2.0...@metamask/smart-accounts-kit@0.3.0
|
|
27
35
|
[0.2.0]: https://github.com/metamask/smart-accounts-kit/compare/@metamask/smart-accounts-kit@0.1.0...@metamask/smart-accounts-kit@0.2.0
|
|
28
36
|
[0.1.0]: https://github.com/metamask/smart-accounts-kit/releases/tag/@metamask/smart-accounts-kit@0.1.0
|
package/dist/actions/index.cjs
CHANGED
|
@@ -14,11 +14,11 @@
|
|
|
14
14
|
|
|
15
15
|
|
|
16
16
|
|
|
17
|
-
var
|
|
18
|
-
require('../chunk-
|
|
19
|
-
require('../chunk-
|
|
17
|
+
var _chunkQPCM4XRTcjs = require('../chunk-QPCM4XRT.cjs');
|
|
18
|
+
require('../chunk-4QBJFYZ7.cjs');
|
|
19
|
+
require('../chunk-BWR5ZK6Z.cjs');
|
|
20
20
|
require('../chunk-T6PSFUOZ.cjs');
|
|
21
|
-
require('../chunk-
|
|
21
|
+
require('../chunk-HJETDDBN.cjs');
|
|
22
22
|
|
|
23
23
|
|
|
24
24
|
|
|
@@ -35,5 +35,5 @@ require('../chunk-MAPUND7S.cjs');
|
|
|
35
35
|
|
|
36
36
|
|
|
37
37
|
|
|
38
|
-
exports.caveatEnforcerActions =
|
|
38
|
+
exports.caveatEnforcerActions = _chunkQPCM4XRTcjs.caveatEnforcerActions; exports.erc7710BundlerActions = _chunkQPCM4XRTcjs.erc7710BundlerActions; exports.erc7710WalletActions = _chunkQPCM4XRTcjs.erc7710WalletActions; exports.erc7715ProviderActions = _chunkQPCM4XRTcjs.erc7715ProviderActions; exports.getErc20PeriodTransferEnforcerAvailableAmount = _chunkQPCM4XRTcjs.getErc20PeriodTransferEnforcerAvailableAmount; exports.getErc20StreamingEnforcerAvailableAmount = _chunkQPCM4XRTcjs.getErc20StreamingEnforcerAvailableAmount; exports.getMultiTokenPeriodEnforcerAvailableAmount = _chunkQPCM4XRTcjs.getMultiTokenPeriodEnforcerAvailableAmount; exports.getNativeTokenPeriodTransferEnforcerAvailableAmount = _chunkQPCM4XRTcjs.getNativeTokenPeriodTransferEnforcerAvailableAmount; exports.getNativeTokenStreamingEnforcerAvailableAmount = _chunkQPCM4XRTcjs.getNativeTokenStreamingEnforcerAvailableAmount; exports.isValid7702Implementation = _chunkQPCM4XRTcjs.isValid7702Implementation; exports.requestExecutionPermissions = _chunkQPCM4XRTcjs.erc7715RequestExecutionPermissionsAction; exports.signDelegation = _chunkQPCM4XRTcjs.signDelegation; exports.signDelegationActions = _chunkQPCM4XRTcjs.signDelegationActions; exports.signUserOperation = _chunkQPCM4XRTcjs.signUserOperation; exports.signUserOperationActions = _chunkQPCM4XRTcjs.signUserOperationActions;
|
|
39
39
|
//# sourceMappingURL=index.cjs.map
|
package/dist/actions/index.mjs
CHANGED
|
@@ -14,11 +14,11 @@ import {
|
|
|
14
14
|
signDelegationActions,
|
|
15
15
|
signUserOperation,
|
|
16
16
|
signUserOperationActions
|
|
17
|
-
} from "../chunk-
|
|
18
|
-
import "../chunk-
|
|
19
|
-
import "../chunk-
|
|
17
|
+
} from "../chunk-2HNEALPY.mjs";
|
|
18
|
+
import "../chunk-F5U55BIP.mjs";
|
|
19
|
+
import "../chunk-3JBYBEYP.mjs";
|
|
20
20
|
import "../chunk-CPLIK3VF.mjs";
|
|
21
|
-
import "../chunk-
|
|
21
|
+
import "../chunk-BJGZGTRU.mjs";
|
|
22
22
|
export {
|
|
23
23
|
caveatEnforcerActions,
|
|
24
24
|
erc7710BundlerActions,
|
|
@@ -4,11 +4,11 @@ import {
|
|
|
4
4
|
read_exports3,
|
|
5
5
|
read_exports4,
|
|
6
6
|
read_exports5
|
|
7
|
-
} from "./chunk-
|
|
7
|
+
} from "./chunk-F5U55BIP.mjs";
|
|
8
8
|
import {
|
|
9
9
|
getSmartAccountsEnvironment,
|
|
10
10
|
prepareSignUserOperationTypedData
|
|
11
|
-
} from "./chunk-
|
|
11
|
+
} from "./chunk-3JBYBEYP.mjs";
|
|
12
12
|
import {
|
|
13
13
|
createExecution,
|
|
14
14
|
encodeExecutionCalldatas
|
|
@@ -17,7 +17,7 @@ import {
|
|
|
17
17
|
__export,
|
|
18
18
|
getDelegationHashOffchain,
|
|
19
19
|
prepareSignDelegationTypedData
|
|
20
|
-
} from "./chunk-
|
|
20
|
+
} from "./chunk-BJGZGTRU.mjs";
|
|
21
21
|
|
|
22
22
|
// src/actions/index.ts
|
|
23
23
|
var actions_exports = {};
|
|
@@ -748,4 +748,4 @@ export {
|
|
|
748
748
|
erc7710BundlerActions,
|
|
749
749
|
actions_exports
|
|
750
750
|
};
|
|
751
|
-
//# sourceMappingURL=chunk-
|
|
751
|
+
//# sourceMappingURL=chunk-2HNEALPY.mjs.map
|
|
@@ -3,7 +3,7 @@ import {
|
|
|
3
3
|
} from "./chunk-CPLIK3VF.mjs";
|
|
4
4
|
import {
|
|
5
5
|
encodePermissionContexts
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-BJGZGTRU.mjs";
|
|
7
7
|
|
|
8
8
|
// src/write.ts
|
|
9
9
|
import { SimpleFactory, DelegationManager } from "@metamask/delegation-abis";
|
|
@@ -333,4 +333,4 @@ export {
|
|
|
333
333
|
prepareSignUserOperationTypedData,
|
|
334
334
|
signUserOperation
|
|
335
335
|
};
|
|
336
|
-
//# sourceMappingURL=chunk-
|
|
336
|
+
//# sourceMappingURL=chunk-3JBYBEYP.mjs.map
|
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var _chunkHJETDDBNcjs = require('./chunk-HJETDDBN.cjs');
|
|
4
4
|
|
|
5
5
|
// src/DelegationFramework/ERC20PeriodTransferEnforcer/index.ts
|
|
6
6
|
var ERC20PeriodTransferEnforcer_exports = {};
|
|
7
|
-
|
|
7
|
+
_chunkHJETDDBNcjs.__export.call(void 0, ERC20PeriodTransferEnforcer_exports, {
|
|
8
8
|
read: () => read_exports
|
|
9
9
|
});
|
|
10
10
|
|
|
11
11
|
// src/DelegationFramework/ERC20PeriodTransferEnforcer/read.ts
|
|
12
12
|
var read_exports = {};
|
|
13
|
-
|
|
13
|
+
_chunkHJETDDBNcjs.__export.call(void 0, read_exports, {
|
|
14
14
|
getAvailableAmount: () => read
|
|
15
15
|
});
|
|
16
16
|
|
|
@@ -42,13 +42,13 @@ var read = async ({
|
|
|
42
42
|
|
|
43
43
|
// src/DelegationFramework/ERC20StreamingEnforcer/index.ts
|
|
44
44
|
var ERC20StreamingEnforcer_exports = {};
|
|
45
|
-
|
|
45
|
+
_chunkHJETDDBNcjs.__export.call(void 0, ERC20StreamingEnforcer_exports, {
|
|
46
46
|
read: () => read_exports2
|
|
47
47
|
});
|
|
48
48
|
|
|
49
49
|
// src/DelegationFramework/ERC20StreamingEnforcer/read.ts
|
|
50
50
|
var read_exports2 = {};
|
|
51
|
-
|
|
51
|
+
_chunkHJETDDBNcjs.__export.call(void 0, read_exports2, {
|
|
52
52
|
getAvailableAmount: () => read2
|
|
53
53
|
});
|
|
54
54
|
|
|
@@ -126,13 +126,13 @@ function getAvailableAmount(allowance) {
|
|
|
126
126
|
|
|
127
127
|
// src/DelegationFramework/MultiTokenPeriodEnforcer/index.ts
|
|
128
128
|
var MultiTokenPeriodEnforcer_exports = {};
|
|
129
|
-
|
|
129
|
+
_chunkHJETDDBNcjs.__export.call(void 0, MultiTokenPeriodEnforcer_exports, {
|
|
130
130
|
read: () => read_exports3
|
|
131
131
|
});
|
|
132
132
|
|
|
133
133
|
// src/DelegationFramework/MultiTokenPeriodEnforcer/read.ts
|
|
134
134
|
var read_exports3 = {};
|
|
135
|
-
|
|
135
|
+
_chunkHJETDDBNcjs.__export.call(void 0, read_exports3, {
|
|
136
136
|
getAvailableAmount: () => read3
|
|
137
137
|
});
|
|
138
138
|
|
|
@@ -165,13 +165,13 @@ var read3 = async ({
|
|
|
165
165
|
|
|
166
166
|
// src/DelegationFramework/NativeTokenPeriodTransferEnforcer/index.ts
|
|
167
167
|
var NativeTokenPeriodTransferEnforcer_exports = {};
|
|
168
|
-
|
|
168
|
+
_chunkHJETDDBNcjs.__export.call(void 0, NativeTokenPeriodTransferEnforcer_exports, {
|
|
169
169
|
read: () => read_exports4
|
|
170
170
|
});
|
|
171
171
|
|
|
172
172
|
// src/DelegationFramework/NativeTokenPeriodTransferEnforcer/read.ts
|
|
173
173
|
var read_exports4 = {};
|
|
174
|
-
|
|
174
|
+
_chunkHJETDDBNcjs.__export.call(void 0, read_exports4, {
|
|
175
175
|
getAvailableAmount: () => read4
|
|
176
176
|
});
|
|
177
177
|
|
|
@@ -203,13 +203,13 @@ var read4 = async ({
|
|
|
203
203
|
|
|
204
204
|
// src/DelegationFramework/NativeTokenStreamingEnforcer/index.ts
|
|
205
205
|
var NativeTokenStreamingEnforcer_exports = {};
|
|
206
|
-
|
|
206
|
+
_chunkHJETDDBNcjs.__export.call(void 0, NativeTokenStreamingEnforcer_exports, {
|
|
207
207
|
read: () => read_exports5
|
|
208
208
|
});
|
|
209
209
|
|
|
210
210
|
// src/DelegationFramework/NativeTokenStreamingEnforcer/read.ts
|
|
211
211
|
var read_exports5 = {};
|
|
212
|
-
|
|
212
|
+
_chunkHJETDDBNcjs.__export.call(void 0, read_exports5, {
|
|
213
213
|
getAvailableAmount: () => read5
|
|
214
214
|
});
|
|
215
215
|
|
|
@@ -296,4 +296,4 @@ function getAvailableAmount2(allowance) {
|
|
|
296
296
|
|
|
297
297
|
|
|
298
298
|
exports.read_exports = read_exports; exports.ERC20PeriodTransferEnforcer_exports = ERC20PeriodTransferEnforcer_exports; exports.read_exports2 = read_exports2; exports.ERC20StreamingEnforcer_exports = ERC20StreamingEnforcer_exports; exports.read_exports3 = read_exports3; exports.MultiTokenPeriodEnforcer_exports = MultiTokenPeriodEnforcer_exports; exports.read_exports4 = read_exports4; exports.NativeTokenPeriodTransferEnforcer_exports = NativeTokenPeriodTransferEnforcer_exports; exports.read_exports5 = read_exports5; exports.NativeTokenStreamingEnforcer_exports = NativeTokenStreamingEnforcer_exports;
|
|
299
|
-
//# sourceMappingURL=chunk-
|
|
299
|
+
//# sourceMappingURL=chunk-4QBJFYZ7.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/home/runner/work/smart-accounts-kit/smart-accounts-kit/packages/smart-accounts-kit/dist/chunk-PZM5E7L3.cjs","../src/DelegationFramework/ERC20PeriodTransferEnforcer/index.ts","../src/DelegationFramework/ERC20PeriodTransferEnforcer/read.ts","../src/DelegationFramework/ERC20PeriodTransferEnforcer/methods/getAvailableAmount.ts","../src/DelegationFramework/ERC20StreamingEnforcer/index.ts","../src/DelegationFramework/ERC20StreamingEnforcer/read.ts","../src/DelegationFramework/ERC20StreamingEnforcer/methods/getAvailableAmount.ts","../src/DelegationFramework/MultiTokenPeriodEnforcer/index.ts","../src/DelegationFramework/MultiTokenPeriodEnforcer/read.ts","../src/DelegationFramework/MultiTokenPeriodEnforcer/methods/getAvailableAmount.ts","../src/DelegationFramework/NativeTokenPeriodTransferEnforcer/index.ts","../src/DelegationFramework/NativeTokenPeriodTransferEnforcer/read.ts","../src/DelegationFramework/NativeTokenPeriodTransferEnforcer/methods/getAvailableAmount.ts","../src/DelegationFramework/NativeTokenStreamingEnforcer/index.ts","../src/DelegationFramework/NativeTokenStreamingEnforcer/read.ts","../src/DelegationFramework/NativeTokenStreamingEnforcer/methods/getAvailableAmount.ts"],"names":["read_exports","read","readContract","availableAmount","getBlock","getAvailableAmount"],"mappings":"AAAA;AACE;AACF,wDAA6B;AAC7B;AACA;ACJA,IAAA,oCAAA,EAAA,CAAA,CAAA;AAAA,wCAAA,mCAAA,EAAA;AAAA,EAAA,IAAA,EAAA,CAAA,EAAA,GAAA;AAAA,CAAA,CAAA;ADSA;AACA;AEVA,IAAA,aAAA,EAAA,CAAA,CAAA;AAAA,wCAAA,YAAA,EAAA;AAAA,EAAA,kBAAA,EAAA,CAAA,EAAA,GAAA;AAAA,CAAA,CAAA;AFeA;AACA;AGhBA,2DAA4C;AAE5C,uCAA6B;AAUtB,IAAM,KAAA,EAAO,MAAA,CAAO;AAAA,EACzB,MAAA;AAAA,EACA,eAAA;AAAA,EACA,cAAA;AAAA,EACA,iBAAA;AAAA,EACA;AACF,CAAA,EAAA,GAAwC;AACtC,EAAA,MAAM,CAAC,eAAA,EAAiB,WAAA,EAAa,aAAa,EAAA,EAAI,MAAM,mCAAA;AAAA,IAC1D,MAAA;AAAA,IACA;AAAA,MACE,OAAA,EAAS,eAAA;AAAA,MACT,GAAA,EAAK,2CAAA,CAA4B,GAAA;AAAA,MACjC,YAAA,EAAc,oBAAA;AAAA,MACd,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AA,CAAU,iBAAA,EAAmB,SAAA,CAAU,SAAA,EAAW;AACpD,IAAA,OAAO,EAAA;AAAA,EACT;AAGA,EAAA,MAAM,QAAA,EAAU,SAAA,CAAU,iBAAA,EAAmB,SAAA,CAAU,SAAA;AAGvD,EAAA,IAAI,SAAA,EAAW,SAAA,CAAU,cAAA,EAAgB,SAAA,CAAU,gBAAA,EAAkB,OAAA;AAGrE,EAAA,GAAA,CAAI,SAAA,EAAW,SAAA,CAAU,SAAA,EAAW;AAClC,IAAA,SAAA,EAAW,SAAA,CAAU,SAAA;AAAA,EACvB;AAGA,EAAA,GAAA,CAAI,SAAA,CAAU,MAAA,GAAS,QAAA,EAAU;AAC/B,IAAA,OAAO,EAAA;AAAA,EACT;AAGA,EAAA,OAAO,SAAA,EAAW,SAAA,CAAU,KAAA;AAC9B;AfiKA;AACA;AACE;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACF,6lBAAC","file":"/home/runner/work/smart-accounts-kit/smart-accounts-kit/packages/smart-accounts-kit/dist/chunk-PZM5E7L3.cjs","sourcesContent":[null,"import * as read from './read';\n\nexport { read };\n","import { read as getAvailableAmount } from './methods/getAvailableAmount';\n\nexport { getAvailableAmount };\n","import { ERC20PeriodTransferEnforcer } from '@metamask/delegation-abis';\nimport type { Address, Client, Hex } from 'viem';\nimport { readContract } from 'viem/actions';\n\nexport type ReadGetAvailableAmountParameters = {\n client: Client;\n contractAddress: Address;\n delegationHash: Hex;\n delegationManager: Address;\n terms: Hex;\n};\n\nexport const read = async ({\n client,\n contractAddress,\n delegationHash,\n delegationManager,\n terms,\n}: ReadGetAvailableAmountParameters) => {\n const [availableAmount, isNewPeriod, currentPeriod] = await readContract(\n client,\n {\n address: contractAddress,\n abi: ERC20PeriodTransferEnforcer.abi,\n functionName: 'getAvailableAmount',\n args: [delegationHash, delegationManager, terms],\n },\n );\n\n return {\n availableAmount,\n isNewPeriod,\n currentPeriod,\n };\n};\n","import * as read from './read';\n\nexport { read };\n","import { read as getAvailableAmount } from './methods/getAvailableAmount';\n\nexport { getAvailableAmount };\n","import { ERC20StreamingEnforcer } from '@metamask/delegation-abis';\nimport type { Address, Client, Hex } from 'viem';\nimport { readContract, getBlock } from 'viem/actions';\n\nexport type ReadGetAvailableAmountParameters = {\n client: Client;\n contractAddress: Address;\n delegationManager: Address;\n delegationHash: Hex;\n terms: Hex;\n};\n\nexport const read = async ({\n client,\n contractAddress,\n delegationManager,\n delegationHash,\n terms,\n}: ReadGetAvailableAmountParameters) => {\n // Get current block timestamp from blockchain\n const currentBlock = await getBlock(client);\n const currentTimestamp = currentBlock.timestamp;\n\n // First, get the current state from the contract\n const allowanceState = await readContract(client, {\n address: contractAddress,\n abi: ERC20StreamingEnforcer.abi,\n functionName: 'streamingAllowances',\n args: [delegationManager, delegationHash],\n });\n\n const [initialAmount, maxAmount, amountPerSecond, startTime, spent] =\n allowanceState;\n\n // Check if state exists (startTime != 0)\n if (startTime !== 0n) {\n // State exists, calculate available amount using the stored state\n const availableAmount = getAvailableAmount({\n initialAmount,\n maxAmount,\n amountPerSecond,\n startTime,\n spent,\n currentTimestamp,\n });\n\n return {\n availableAmount,\n };\n }\n\n // State doesn't exist, decode terms and simulate with spent = 0\n const decodedTerms = await readContract(client, {\n address: contractAddress,\n abi: ERC20StreamingEnforcer.abi,\n functionName: 'getTermsInfo',\n args: [terms],\n });\n\n const [\n ,\n decodedInitialAmount,\n decodedMaxAmount,\n decodedAmountPerSecond,\n decodedStartTime,\n ] = decodedTerms;\n\n // Simulate using decoded terms with spent = 0\n const availableAmount = getAvailableAmount({\n initialAmount: decodedInitialAmount,\n maxAmount: decodedMaxAmount,\n amountPerSecond: decodedAmountPerSecond,\n startTime: decodedStartTime,\n spent: 0n,\n currentTimestamp,\n });\n\n return {\n availableAmount,\n };\n};\n\n/**\n * Replicates the internal _getAvailableAmount logic from the smart contract.\n *\n * @param allowance - The allowance object containing all parameters.\n * @param allowance.initialAmount - The initial amount available.\n * @param allowance.maxAmount - The maximum amount allowed.\n * @param allowance.amountPerSecond - The amount streamed per second.\n * @param allowance.startTime - The start time of the streaming.\n * @param allowance.spent - The amount already spent.\n * @param allowance.currentTimestamp - The current timestamp.\n * @returns The available amount that can be spent.\n */\nfunction getAvailableAmount(allowance: {\n initialAmount: bigint;\n maxAmount: bigint;\n amountPerSecond: bigint;\n startTime: bigint;\n spent: bigint;\n currentTimestamp: bigint;\n}): bigint {\n // If current time is before start time, nothing is available\n if (allowance.currentTimestamp < allowance.startTime) {\n return 0n;\n }\n\n // Calculate elapsed time since start\n const elapsed = allowance.currentTimestamp - allowance.startTime;\n\n // Calculate total unlocked amount\n let unlocked = allowance.initialAmount + allowance.amountPerSecond * elapsed;\n\n // Cap by max amount\n if (unlocked > allowance.maxAmount) {\n unlocked = allowance.maxAmount;\n }\n\n // If spent >= unlocked, nothing available\n if (allowance.spent >= unlocked) {\n return 0n;\n }\n\n // Return available amount\n return unlocked - allowance.spent;\n}\n","import * as read from './read';\n\nexport { read };\n","import { read as getAvailableAmount } from './methods/getAvailableAmount';\n\nexport { getAvailableAmount };\n","import { MultiTokenPeriodEnforcer } from '@metamask/delegation-abis';\nimport type { Address, Client, Hex } from 'viem';\nimport { readContract } from 'viem/actions';\n\nexport type ReadGetAvailableAmountParameters = {\n client: Client;\n contractAddress: Address;\n delegationHash: Hex;\n delegationManager: Address;\n terms: Hex;\n args: Hex;\n};\n\nexport const read = async ({\n client,\n contractAddress,\n delegationHash,\n delegationManager,\n terms,\n args,\n}: ReadGetAvailableAmountParameters) => {\n const [availableAmount, isNewPeriod, currentPeriod] = await readContract(\n client,\n {\n address: contractAddress,\n abi: MultiTokenPeriodEnforcer.abi,\n functionName: 'getAvailableAmount',\n args: [delegationHash, delegationManager, terms, args],\n },\n );\n\n return {\n availableAmount,\n isNewPeriod,\n currentPeriod,\n };\n};\n","import * as read from './read';\n\nexport { read };\n","import { read as getAvailableAmount } from './methods/getAvailableAmount';\n\nexport { getAvailableAmount };\n","import { NativeTokenPeriodTransferEnforcer } from '@metamask/delegation-abis';\nimport type { Address, Client, Hex } from 'viem';\nimport { readContract } from 'viem/actions';\n\nexport type ReadGetAvailableAmountParameters = {\n client: Client;\n contractAddress: Address;\n delegationHash: Hex;\n delegationManager: Address;\n terms: Hex;\n};\n\nexport const read = async ({\n client,\n contractAddress,\n delegationHash,\n delegationManager,\n terms,\n}: ReadGetAvailableAmountParameters) => {\n const [availableAmount, isNewPeriod, currentPeriod] = await readContract(\n client,\n {\n address: contractAddress,\n abi: NativeTokenPeriodTransferEnforcer.abi,\n functionName: 'getAvailableAmount',\n args: [delegationHash, delegationManager, terms],\n },\n );\n\n return {\n availableAmount,\n isNewPeriod,\n currentPeriod,\n };\n};\n","import * as read from './read';\n\nexport { read };\n","import { read as getAvailableAmount } from './methods/getAvailableAmount';\n\nexport { getAvailableAmount };\n","import { NativeTokenStreamingEnforcer } from '@metamask/delegation-abis';\nimport type { Address, Client, Hex } from 'viem';\nimport { readContract, getBlock } from 'viem/actions';\n\nexport type ReadGetAvailableAmountParameters = {\n client: Client;\n contractAddress: Address;\n delegationManager: Address;\n delegationHash: Hex;\n terms: Hex;\n};\n\nexport const read = async ({\n client,\n contractAddress,\n delegationManager,\n delegationHash,\n terms,\n}: ReadGetAvailableAmountParameters) => {\n // Get current block timestamp from blockchain\n const currentBlock = await getBlock(client);\n const currentTimestamp = currentBlock.timestamp;\n\n // First, get the current state from the contract\n const allowanceState = await readContract(client, {\n address: contractAddress,\n abi: NativeTokenStreamingEnforcer.abi,\n functionName: 'streamingAllowances',\n args: [delegationManager, delegationHash],\n });\n\n const [initialAmount, maxAmount, amountPerSecond, startTime, spent] =\n allowanceState;\n\n // Check if state exists (startTime != 0)\n if (startTime !== 0n) {\n // State exists, calculate available amount using the stored state\n const availableAmount = getAvailableAmount({\n initialAmount,\n maxAmount,\n amountPerSecond,\n startTime,\n spent,\n currentTimestamp,\n });\n\n return {\n availableAmount,\n };\n }\n\n // State doesn't exist, decode terms and simulate with spent = 0\n const decodedTerms = await readContract(client, {\n address: contractAddress,\n abi: NativeTokenStreamingEnforcer.abi,\n functionName: 'getTermsInfo',\n args: [terms],\n });\n\n const [\n decodedInitialAmount,\n decodedMaxAmount,\n decodedAmountPerSecond,\n decodedStartTime,\n ] = decodedTerms;\n\n // Simulate using decoded terms with spent = 0\n const availableAmount = getAvailableAmount({\n initialAmount: decodedInitialAmount,\n maxAmount: decodedMaxAmount,\n amountPerSecond: decodedAmountPerSecond,\n startTime: decodedStartTime,\n spent: 0n,\n currentTimestamp,\n });\n\n return {\n availableAmount,\n };\n};\n\n/**\n * Replicates the internal _getAvailableAmount logic from the smart contract.\n *\n * @param allowance - The allowance object containing all parameters.\n * @param allowance.initialAmount - The initial amount available.\n * @param allowance.maxAmount - The maximum amount allowed.\n * @param allowance.amountPerSecond - The amount streamed per second.\n * @param allowance.startTime - The start time of the streaming.\n * @param allowance.spent - The amount already spent.\n * @param allowance.currentTimestamp - The current timestamp.\n * @returns The available amount that can be spent.\n */\nfunction getAvailableAmount(allowance: {\n initialAmount: bigint;\n maxAmount: bigint;\n amountPerSecond: bigint;\n startTime: bigint;\n spent: bigint;\n currentTimestamp: bigint;\n}): bigint {\n // If current time is before start time, nothing is available\n if (allowance.currentTimestamp < allowance.startTime) {\n return 0n;\n }\n\n // Calculate elapsed time since start\n const elapsed = allowance.currentTimestamp - allowance.startTime;\n\n // Calculate total unlocked amount\n let unlocked = allowance.initialAmount + allowance.amountPerSecond * elapsed;\n\n // Cap by max amount\n if (unlocked > allowance.maxAmount) {\n unlocked = allowance.maxAmount;\n }\n\n // If spent >= unlocked, nothing available\n if (allowance.spent >= unlocked) {\n return 0n;\n }\n\n // Return available amount\n return unlocked - allowance.spent;\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["/home/runner/work/smart-accounts-kit/smart-accounts-kit/packages/smart-accounts-kit/dist/chunk-4QBJFYZ7.cjs","../src/DelegationFramework/ERC20PeriodTransferEnforcer/index.ts","../src/DelegationFramework/ERC20PeriodTransferEnforcer/read.ts","../src/DelegationFramework/ERC20PeriodTransferEnforcer/methods/getAvailableAmount.ts","../src/DelegationFramework/ERC20StreamingEnforcer/index.ts","../src/DelegationFramework/ERC20StreamingEnforcer/read.ts","../src/DelegationFramework/ERC20StreamingEnforcer/methods/getAvailableAmount.ts","../src/DelegationFramework/MultiTokenPeriodEnforcer/index.ts","../src/DelegationFramework/MultiTokenPeriodEnforcer/read.ts","../src/DelegationFramework/MultiTokenPeriodEnforcer/methods/getAvailableAmount.ts","../src/DelegationFramework/NativeTokenPeriodTransferEnforcer/index.ts","../src/DelegationFramework/NativeTokenPeriodTransferEnforcer/read.ts","../src/DelegationFramework/NativeTokenPeriodTransferEnforcer/methods/getAvailableAmount.ts","../src/DelegationFramework/NativeTokenStreamingEnforcer/index.ts","../src/DelegationFramework/NativeTokenStreamingEnforcer/read.ts","../src/DelegationFramework/NativeTokenStreamingEnforcer/methods/getAvailableAmount.ts"],"names":["read_exports","read","readContract","availableAmount","getBlock","getAvailableAmount"],"mappings":"AAAA;AACE;AACF,wDAA6B;AAC7B;AACA;ACJA,IAAA,oCAAA,EAAA,CAAA,CAAA;AAAA,wCAAA,mCAAA,EAAA;AAAA,EAAA,IAAA,EAAA,CAAA,EAAA,GAAA;AAAA,CAAA,CAAA;ADSA;AACA;AEVA,IAAA,aAAA,EAAA,CAAA,CAAA;AAAA,wCAAA,YAAA,EAAA;AAAA,EAAA,kBAAA,EAAA,CAAA,EAAA,GAAA;AAAA,CAAA,CAAA;AFeA;AACA;AGhBA,2DAA4C;AAE5C,uCAA6B;AAUtB,IAAM,KAAA,EAAO,MAAA,CAAO;AAAA,EACzB,MAAA;AAAA,EACA,eAAA;AAAA,EACA,cAAA;AAAA,EACA,iBAAA;AAAA,EACA;AACF,CAAA,EAAA,GAAwC;AACtC,EAAA,MAAM,CAAC,eAAA,EAAiB,WAAA,EAAa,aAAa,EAAA,EAAI,MAAM,mCAAA;AAAA,IAC1D,MAAA;AAAA,IACA;AAAA,MACE,OAA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,IACL;AAAA,EACF,CAAA;AACF,CAAA;AAcA,SAASA,mBAAAA,CAAmB,SAAA,EAOjB;AAET,EAAA,GAAA,CAAI,SAAA,CAAU,iBAAA,EAAmB,SAAA,CAAU,SAAA,EAAW;AACpD,IAAA,OAAO,EAAA;AAAA,EACT;AAGA,EAAA,MAAM,QAAA,EAAU,SAAA,CAAU,iBAAA,EAAmB,SAAA,CAAU,SAAA;AAGvD,EAAA,IAAI,SAAA,EAAW,SAAA,CAAU,cAAA,EAAgB,SAAA,CAAU,gBAAA,EAAkB,OAAA;AAGrE,EAAA,GAAA,CAAI,SAAA,EAAW,SAAA,CAAU,SAAA,EAAW;AAClC,IAAA,SAAA,EAAW,SAAA,CAAU,SAAA;AAAA,EACvB;AAGA,EAAA,GAAA,CAAI,SAAA,CAAU,MAAA,GAAS,QAAA,EAAU;AAC/B,IAAA,OAAO,EAAA;AAAA,EACT;AAGA,EAAA,OAAO,SAAA,EAAW,SAAA,CAAU,KAAA;AAC9B;AfiKA;AACA;AACE;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACF,6lBAAC","file":"/home/runner/work/smart-accounts-kit/smart-accounts-kit/packages/smart-accounts-kit/dist/chunk-4QBJFYZ7.cjs","sourcesContent":[null,"import * as read from './read';\n\nexport { read };\n","import { read as getAvailableAmount } from './methods/getAvailableAmount';\n\nexport { getAvailableAmount };\n","import { ERC20PeriodTransferEnforcer } from '@metamask/delegation-abis';\nimport type { Address, Client, Hex } from 'viem';\nimport { readContract } from 'viem/actions';\n\nexport type ReadGetAvailableAmountParameters = {\n client: Client;\n contractAddress: Address;\n delegationHash: Hex;\n delegationManager: Address;\n terms: Hex;\n};\n\nexport const read = async ({\n client,\n contractAddress,\n delegationHash,\n delegationManager,\n terms,\n}: ReadGetAvailableAmountParameters) => {\n const [availableAmount, isNewPeriod, currentPeriod] = await readContract(\n client,\n {\n address: contractAddress,\n abi: ERC20PeriodTransferEnforcer.abi,\n functionName: 'getAvailableAmount',\n args: [delegationHash, delegationManager, terms],\n },\n );\n\n return {\n availableAmount,\n isNewPeriod,\n currentPeriod,\n };\n};\n","import * as read from './read';\n\nexport { read };\n","import { read as getAvailableAmount } from './methods/getAvailableAmount';\n\nexport { getAvailableAmount };\n","import { ERC20StreamingEnforcer } from '@metamask/delegation-abis';\nimport type { Address, Client, Hex } from 'viem';\nimport { readContract, getBlock } from 'viem/actions';\n\nexport type ReadGetAvailableAmountParameters = {\n client: Client;\n contractAddress: Address;\n delegationManager: Address;\n delegationHash: Hex;\n terms: Hex;\n};\n\nexport const read = async ({\n client,\n contractAddress,\n delegationManager,\n delegationHash,\n terms,\n}: ReadGetAvailableAmountParameters) => {\n // Get current block timestamp from blockchain\n const currentBlock = await getBlock(client);\n const currentTimestamp = currentBlock.timestamp;\n\n // First, get the current state from the contract\n const allowanceState = await readContract(client, {\n address: contractAddress,\n abi: ERC20StreamingEnforcer.abi,\n functionName: 'streamingAllowances',\n args: [delegationManager, delegationHash],\n });\n\n const [initialAmount, maxAmount, amountPerSecond, startTime, spent] =\n allowanceState;\n\n // Check if state exists (startTime != 0)\n if (startTime !== 0n) {\n // State exists, calculate available amount using the stored state\n const availableAmount = getAvailableAmount({\n initialAmount,\n maxAmount,\n amountPerSecond,\n startTime,\n spent,\n currentTimestamp,\n });\n\n return {\n availableAmount,\n };\n }\n\n // State doesn't exist, decode terms and simulate with spent = 0\n const decodedTerms = await readContract(client, {\n address: contractAddress,\n abi: ERC20StreamingEnforcer.abi,\n functionName: 'getTermsInfo',\n args: [terms],\n });\n\n const [\n ,\n decodedInitialAmount,\n decodedMaxAmount,\n decodedAmountPerSecond,\n decodedStartTime,\n ] = decodedTerms;\n\n // Simulate using decoded terms with spent = 0\n const availableAmount = getAvailableAmount({\n initialAmount: decodedInitialAmount,\n maxAmount: decodedMaxAmount,\n amountPerSecond: decodedAmountPerSecond,\n startTime: decodedStartTime,\n spent: 0n,\n currentTimestamp,\n });\n\n return {\n availableAmount,\n };\n};\n\n/**\n * Replicates the internal _getAvailableAmount logic from the smart contract.\n *\n * @param allowance - The allowance object containing all parameters.\n * @param allowance.initialAmount - The initial amount available.\n * @param allowance.maxAmount - The maximum amount allowed.\n * @param allowance.amountPerSecond - The amount streamed per second.\n * @param allowance.startTime - The start time of the streaming.\n * @param allowance.spent - The amount already spent.\n * @param allowance.currentTimestamp - The current timestamp.\n * @returns The available amount that can be spent.\n */\nfunction getAvailableAmount(allowance: {\n initialAmount: bigint;\n maxAmount: bigint;\n amountPerSecond: bigint;\n startTime: bigint;\n spent: bigint;\n currentTimestamp: bigint;\n}): bigint {\n // If current time is before start time, nothing is available\n if (allowance.currentTimestamp < allowance.startTime) {\n return 0n;\n }\n\n // Calculate elapsed time since start\n const elapsed = allowance.currentTimestamp - allowance.startTime;\n\n // Calculate total unlocked amount\n let unlocked = allowance.initialAmount + allowance.amountPerSecond * elapsed;\n\n // Cap by max amount\n if (unlocked > allowance.maxAmount) {\n unlocked = allowance.maxAmount;\n }\n\n // If spent >= unlocked, nothing available\n if (allowance.spent >= unlocked) {\n return 0n;\n }\n\n // Return available amount\n return unlocked - allowance.spent;\n}\n","import * as read from './read';\n\nexport { read };\n","import { read as getAvailableAmount } from './methods/getAvailableAmount';\n\nexport { getAvailableAmount };\n","import { MultiTokenPeriodEnforcer } from '@metamask/delegation-abis';\nimport type { Address, Client, Hex } from 'viem';\nimport { readContract } from 'viem/actions';\n\nexport type ReadGetAvailableAmountParameters = {\n client: Client;\n contractAddress: Address;\n delegationHash: Hex;\n delegationManager: Address;\n terms: Hex;\n args: Hex;\n};\n\nexport const read = async ({\n client,\n contractAddress,\n delegationHash,\n delegationManager,\n terms,\n args,\n}: ReadGetAvailableAmountParameters) => {\n const [availableAmount, isNewPeriod, currentPeriod] = await readContract(\n client,\n {\n address: contractAddress,\n abi: MultiTokenPeriodEnforcer.abi,\n functionName: 'getAvailableAmount',\n args: [delegationHash, delegationManager, terms, args],\n },\n );\n\n return {\n availableAmount,\n isNewPeriod,\n currentPeriod,\n };\n};\n","import * as read from './read';\n\nexport { read };\n","import { read as getAvailableAmount } from './methods/getAvailableAmount';\n\nexport { getAvailableAmount };\n","import { NativeTokenPeriodTransferEnforcer } from '@metamask/delegation-abis';\nimport type { Address, Client, Hex } from 'viem';\nimport { readContract } from 'viem/actions';\n\nexport type ReadGetAvailableAmountParameters = {\n client: Client;\n contractAddress: Address;\n delegationHash: Hex;\n delegationManager: Address;\n terms: Hex;\n};\n\nexport const read = async ({\n client,\n contractAddress,\n delegationHash,\n delegationManager,\n terms,\n}: ReadGetAvailableAmountParameters) => {\n const [availableAmount, isNewPeriod, currentPeriod] = await readContract(\n client,\n {\n address: contractAddress,\n abi: NativeTokenPeriodTransferEnforcer.abi,\n functionName: 'getAvailableAmount',\n args: [delegationHash, delegationManager, terms],\n },\n );\n\n return {\n availableAmount,\n isNewPeriod,\n currentPeriod,\n };\n};\n","import * as read from './read';\n\nexport { read };\n","import { read as getAvailableAmount } from './methods/getAvailableAmount';\n\nexport { getAvailableAmount };\n","import { NativeTokenStreamingEnforcer } from '@metamask/delegation-abis';\nimport type { Address, Client, Hex } from 'viem';\nimport { readContract, getBlock } from 'viem/actions';\n\nexport type ReadGetAvailableAmountParameters = {\n client: Client;\n contractAddress: Address;\n delegationManager: Address;\n delegationHash: Hex;\n terms: Hex;\n};\n\nexport const read = async ({\n client,\n contractAddress,\n delegationManager,\n delegationHash,\n terms,\n}: ReadGetAvailableAmountParameters) => {\n // Get current block timestamp from blockchain\n const currentBlock = await getBlock(client);\n const currentTimestamp = currentBlock.timestamp;\n\n // First, get the current state from the contract\n const allowanceState = await readContract(client, {\n address: contractAddress,\n abi: NativeTokenStreamingEnforcer.abi,\n functionName: 'streamingAllowances',\n args: [delegationManager, delegationHash],\n });\n\n const [initialAmount, maxAmount, amountPerSecond, startTime, spent] =\n allowanceState;\n\n // Check if state exists (startTime != 0)\n if (startTime !== 0n) {\n // State exists, calculate available amount using the stored state\n const availableAmount = getAvailableAmount({\n initialAmount,\n maxAmount,\n amountPerSecond,\n startTime,\n spent,\n currentTimestamp,\n });\n\n return {\n availableAmount,\n };\n }\n\n // State doesn't exist, decode terms and simulate with spent = 0\n const decodedTerms = await readContract(client, {\n address: contractAddress,\n abi: NativeTokenStreamingEnforcer.abi,\n functionName: 'getTermsInfo',\n args: [terms],\n });\n\n const [\n decodedInitialAmount,\n decodedMaxAmount,\n decodedAmountPerSecond,\n decodedStartTime,\n ] = decodedTerms;\n\n // Simulate using decoded terms with spent = 0\n const availableAmount = getAvailableAmount({\n initialAmount: decodedInitialAmount,\n maxAmount: decodedMaxAmount,\n amountPerSecond: decodedAmountPerSecond,\n startTime: decodedStartTime,\n spent: 0n,\n currentTimestamp,\n });\n\n return {\n availableAmount,\n };\n};\n\n/**\n * Replicates the internal _getAvailableAmount logic from the smart contract.\n *\n * @param allowance - The allowance object containing all parameters.\n * @param allowance.initialAmount - The initial amount available.\n * @param allowance.maxAmount - The maximum amount allowed.\n * @param allowance.amountPerSecond - The amount streamed per second.\n * @param allowance.startTime - The start time of the streaming.\n * @param allowance.spent - The amount already spent.\n * @param allowance.currentTimestamp - The current timestamp.\n * @returns The available amount that can be spent.\n */\nfunction getAvailableAmount(allowance: {\n initialAmount: bigint;\n maxAmount: bigint;\n amountPerSecond: bigint;\n startTime: bigint;\n spent: bigint;\n currentTimestamp: bigint;\n}): bigint {\n // If current time is before start time, nothing is available\n if (allowance.currentTimestamp < allowance.startTime) {\n return 0n;\n }\n\n // Calculate elapsed time since start\n const elapsed = allowance.currentTimestamp - allowance.startTime;\n\n // Calculate total unlocked amount\n let unlocked = allowance.initialAmount + allowance.amountPerSecond * elapsed;\n\n // Cap by max amount\n if (unlocked > allowance.maxAmount) {\n unlocked = allowance.maxAmount;\n }\n\n // If spent >= unlocked, nothing available\n if (allowance.spent >= unlocked) {\n return 0n;\n }\n\n // Return available amount\n return unlocked - allowance.spent;\n}\n"]}
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
|
|
6
6
|
|
|
7
7
|
|
|
8
|
-
var
|
|
8
|
+
var _chunkQHDMZSGQcjs = require('./chunk-QHDMZSGQ.cjs');
|
|
9
9
|
|
|
10
10
|
|
|
11
11
|
|
|
@@ -63,7 +63,7 @@ var getCounterfactualAccountData = async ({
|
|
|
63
63
|
y: yValue
|
|
64
64
|
};
|
|
65
65
|
});
|
|
66
|
-
initcode =
|
|
66
|
+
initcode = _chunkQHDMZSGQcjs.encode.call(void 0, { eoaOwner: owner, p256Owners });
|
|
67
67
|
break;
|
|
68
68
|
}
|
|
69
69
|
case "MultiSig" /* MultiSig */: {
|
|
@@ -74,14 +74,14 @@ var getCounterfactualAccountData = async ({
|
|
|
74
74
|
);
|
|
75
75
|
}
|
|
76
76
|
implementationAddress = implementations.MultiSigDeleGatorImpl;
|
|
77
|
-
initcode =
|
|
77
|
+
initcode = _chunkQHDMZSGQcjs.encode2.call(void 0, { owners, threshold });
|
|
78
78
|
break;
|
|
79
79
|
}
|
|
80
80
|
default:
|
|
81
81
|
throw new Error(`Implementation type '${implementation}' not supported`);
|
|
82
82
|
}
|
|
83
83
|
const salt = _viem.pad.call(void 0, deploySalt, { dir: "left", size: 32 });
|
|
84
|
-
const proxyCreationCode =
|
|
84
|
+
const proxyCreationCode = _chunkQHDMZSGQcjs.encodeProxyCreationCode.call(void 0, {
|
|
85
85
|
implementationAddress,
|
|
86
86
|
initcode
|
|
87
87
|
});
|
|
@@ -91,7 +91,7 @@ var getCounterfactualAccountData = async ({
|
|
|
91
91
|
opcode: "CREATE2",
|
|
92
92
|
salt
|
|
93
93
|
});
|
|
94
|
-
const factoryData =
|
|
94
|
+
const factoryData = _chunkQHDMZSGQcjs.encode3.call(void 0, proxyCreationCode, salt);
|
|
95
95
|
return {
|
|
96
96
|
factoryData,
|
|
97
97
|
address
|
|
@@ -136,7 +136,7 @@ var encodeCalls = (calls) => {
|
|
|
136
136
|
if (call && !isDelegatedCall(call)) {
|
|
137
137
|
const { to: target, value, data: callData } = call;
|
|
138
138
|
const execution = _chunkT6PSFUOZcjs.createExecution.call(void 0, { target, value, callData });
|
|
139
|
-
return
|
|
139
|
+
return _chunkQHDMZSGQcjs.encode4.call(void 0, { execution });
|
|
140
140
|
}
|
|
141
141
|
}
|
|
142
142
|
const executions = calls.map((call) => {
|
|
@@ -147,7 +147,7 @@ var encodeCalls = (calls) => {
|
|
|
147
147
|
return _chunkT6PSFUOZcjs.createExecution.call(void 0, { target, value, callData });
|
|
148
148
|
});
|
|
149
149
|
const mode = calls.length === 1 ? "0x0000000000000000000000000000000000000000000000000000000000000000" /* SingleDefault */ : "0x0100000000000000000000000000000000000000000000000000000000000000" /* BatchDefault */;
|
|
150
|
-
return
|
|
150
|
+
return _chunkQHDMZSGQcjs.encode5.call(void 0, { mode, executions });
|
|
151
151
|
};
|
|
152
152
|
var encodeCallsForCaller = async (caller, calls) => {
|
|
153
153
|
if (calls.length === 1) {
|
|
@@ -271,4 +271,4 @@ var createDummyWebAuthnSignature = (keyId) => {
|
|
|
271
271
|
|
|
272
272
|
|
|
273
273
|
exports.Implementation = Implementation; exports.TransferWindow = TransferWindow; exports.getCounterfactualAccountData = getCounterfactualAccountData; exports.encodeCalls = encodeCalls; exports.encodeCallsForCaller = encodeCallsForCaller; exports.SIGNATURE_ABI_PARAMS = SIGNATURE_ABI_PARAMS; exports.encodeDeleGatorSignature = encodeDeleGatorSignature; exports.createDummyWebAuthnSignature = createDummyWebAuthnSignature;
|
|
274
|
-
//# sourceMappingURL=chunk-
|
|
274
|
+
//# sourceMappingURL=chunk-5ZBCTLQS.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/home/runner/work/smart-accounts-kit/smart-accounts-kit/packages/smart-accounts-kit/dist/chunk-AAYEHQXN.cjs","../src/constants.ts","../src/counterfactualAccountData.ts","../src/encodeCalls.ts","../src/webAuthn.ts"],"names":["Implementation","TransferWindow"],"mappings":"AAAA;AACE;AACA;AACA;AACA;AACA;AACA;AACF,wDAA6B;AAC7B;AACE;AACA;AACF,wDA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AA;AAEF,EAAA;AACF;AAEA;AAqBO;AAGL,EAAA;AACA,EAAA;AACA,EAAA;AACA,EAAA;AACE,IAAA;AAAqE,EAAA;AAKvE,EAAA;AAEA,EAAA;AAAO;AAAA,IAAA;AAE+B,EAAA;AAExC;AAQO;AAEL,EAAA;AACA,EAAA;AACA,EAAA;AACA,EAAA;AAEA,EAAA;AACA,EAAA;AAEA,EAAA;AACA,EAAA;AACA,EAAA;AACA,EAAA;AAEA,EAAA;AAAmE,IAAA;AACjE,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,EAAA;AAGF,EAAA;AACF;AJ+DA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA","file":"/home/runner/work/smart-accounts-kit/smart-accounts-kit/packages/smart-accounts-kit/dist/chunk-AAYEHQXN.cjs","sourcesContent":[null,"/**\n * To be used in sdk methods to call Implementation specific code\n * @type {Implementation}\n */\nexport enum Implementation {\n MultiSig = 'MultiSig',\n Hybrid = 'Hybrid',\n Stateless7702 = 'Stateless7702',\n}\n\n/**\n * Represents predefined time intervals (in seconds) for transfer windows.\n * These values are commonly used to specify the duration of transfer periods,\n * such as hourly, daily, weekly, etc., where each enum member's value is the\n * number of seconds in that interval.\n * @enum {number}\n * @property {number} Hourly - 1 hour (3600 seconds)\n * @property {number} Daily - 1 day (86400 seconds)\n * @property {number} Weekly - 1 week (604800 seconds)\n * @property {number} BiWeekly - 2 weeks (1209600 seconds)\n * @property {number} Monthly - 1 month (30 days, 2592000 seconds)\n * @property {number} Quarterly - 1 quarter (90 days, 7776000 seconds)\n * @property {number} Yearly - 1 year (365 days, 31536000 seconds)\n */\nexport enum TransferWindow {\n Hourly = 3600, // 60 * 60 (seconds)\n Daily = 86400, // 60 * 60 * 24 (seconds)\n Weekly = 604800, // 60 * 60 * 24 * 7 (seconds)\n BiWeekly = 1209600, // 60 * 60 * 24 * 14 (seconds)\n Monthly = 2592000, // 60 * 60 * 24 * 30 (seconds)\n Quarterly = 7776000, // 60 * 60 * 24 * 90 (seconds)\n Yearly = 31536000, // 60 * 60 * 24 * 365 (seconds)\n}\n","import type { Address, Hex } from 'viem';\nimport { getContractAddress, pad } from 'viem';\n\nimport { Implementation } from './constants';\nimport { initializeHybridDeleGator } from './DelegationFramework/HybridDeleGator/encode';\nimport { initializeMultiSigDeleGator } from './DelegationFramework/MultiSigDeleGator/encode';\nimport { create2Deploy as encodeCreate2Deploy } from './DelegationFramework/SimpleFactory/encode';\nimport { encodeProxyCreationCode } from './DelegationFramework/utils';\nimport type {\n SmartAccountsEnvironment,\n HybridDeleGatorDeployParams,\n MultiSigDeleGatorDeployParams,\n DeployParams,\n} from './types';\n\n/**\n * Infers counterfactual account data for a DeleGator smart account.\n *\n * @template TImplementation - The type of implementation, extending Implementation.\n * @template TDeployParams - The type of deployment parameters, defaults to DeployParams<Implementation>.\n * @param options - The options for generating counterfactual account data.\n * @param options.factory - The address of the SimpleFactory contract.\n * @param options.implementations - The DeleGator implementation contracts.\n * @param options.implementation - The implementation type to use.\n * @param options.deployParams - The deployment parameters for the specified implementation.\n * @param options.deploySalt - The salt to use for CREATE2 address computation.\n * @returns An object containing the counterfactual address and factory calldata.\n * @description This function calculates the address a DeleGator contract would have if deployed,\n * and provides the calldata needed to deploy it.\n */\nexport const getCounterfactualAccountData = async <\n TImplementation extends Implementation,\n>({\n factory,\n implementations,\n implementation,\n deployParams,\n deploySalt,\n}: {\n factory: Address;\n implementations: SmartAccountsEnvironment['implementations'];\n implementation: TImplementation;\n deployParams: DeployParams<TImplementation>;\n deploySalt: Hex;\n}): Promise<{ factoryData: Hex; address: Address }> => {\n let implementationAddress: Address;\n let initcode: Hex;\n\n switch (implementation) {\n case Implementation.Hybrid: {\n const [owner, keyIds, xValues, yValues] =\n deployParams as HybridDeleGatorDeployParams;\n\n if (!implementations.HybridDeleGatorImpl) {\n throw new Error(\n 'HybridDeleGatorImpl address not provided in environment',\n );\n }\n\n implementationAddress = implementations.HybridDeleGatorImpl;\n\n const p256Owners = keyIds.map((keyId, index) => {\n const xValue = xValues[index];\n const yValue = yValues[index];\n\n if (!xValue || !yValue) {\n throw new Error(\n `Missing X or Y value for keyId ${keyId} at index ${index}`,\n );\n }\n\n return {\n keyId,\n x: xValue,\n y: yValue,\n };\n });\n\n initcode = initializeHybridDeleGator({ eoaOwner: owner, p256Owners });\n break;\n }\n case Implementation.MultiSig: {\n const [owners, threshold] = deployParams as MultiSigDeleGatorDeployParams;\n\n if (!implementations.MultiSigDeleGatorImpl) {\n throw new Error(\n 'MultiSigDeleGatorImpl address not provided in environment',\n );\n }\n\n implementationAddress = implementations.MultiSigDeleGatorImpl;\n initcode = initializeMultiSigDeleGator({ owners, threshold });\n break;\n }\n default:\n throw new Error(`Implementation type '${implementation}' not supported`);\n }\n\n const salt = pad(deploySalt, { dir: 'left', size: 32 });\n\n const proxyCreationCode = encodeProxyCreationCode({\n implementationAddress,\n initcode,\n });\n\n const address = getContractAddress({\n bytecode: proxyCreationCode,\n from: factory,\n opcode: 'CREATE2',\n salt,\n });\n\n const factoryData = encodeCreate2Deploy(proxyCreationCode, salt);\n\n return {\n factoryData,\n address,\n };\n};\n","import { DelegationManager } from '@metamask/delegation-abis';\nimport { encodeFunctionData } from 'viem';\nimport type { Address, Hex } from 'viem';\n\nimport type { DelegatedCall } from './actions/erc7710RedeemDelegationAction';\nimport {\n execute,\n executeWithMode,\n} from './DelegationFramework/DeleGatorCore/encode';\nimport {\n ExecutionMode,\n createExecution,\n encodeExecutionCalldatas,\n} from './executions';\nimport type { Call } from './types';\n\n/**\n * Checks if a call is a delegated call by checking for the presence of permissionsContext and delegationManager.\n *\n * @param call - The call to check.\n * @returns True if the call is a delegated call, false otherwise.\n */\nconst isDelegatedCall = (call: Call): call is DelegatedCall => {\n return 'permissionsContext' in call && 'delegationManager' in call;\n};\n\n/**\n * If there's a single call with permissionsContext and delegationManager,\n * processes it as a delegated call.\n *\n * @param call - The call to process.\n * @returns The execution object for the delegated call.\n * @description\n * This function creates an execution that calls redeemDelegations on the delegation manager.\n */\nconst processDelegatedCall = (call: DelegatedCall) => {\n const {\n permissionsContext,\n delegationManager,\n to: target,\n value,\n data: callData,\n } = call;\n\n const callAsExecution = createExecution({ target, value, callData });\n\n if (!permissionsContext) {\n return callAsExecution;\n }\n\n const redeemCalldata = encodeFunctionData({\n abi: DelegationManager.abi,\n functionName: 'redeemDelegations',\n args: [\n [permissionsContext],\n [ExecutionMode.SingleDefault],\n encodeExecutionCalldatas([[callAsExecution]]),\n ],\n });\n\n return createExecution({\n target: delegationManager,\n callData: redeemCalldata,\n });\n};\n\n/**\n * If there's a single call, encode the shorthand `execute` function. Otherwise, encode the `executeWithMode` function. Execution type will always be \"default\".\n *\n * @param calls - The calls to execute.\n * @returns The encoded calldata for the DeleGator to execute the calls.\n * @description\n * This function supports both single and batch execution modes.\n * For single calls, it uses the gas-efficient execute function.\n */\nexport const encodeCalls = (calls: readonly Call[]) => {\n if (calls.length === 1) {\n const call = calls[0];\n if (call && !isDelegatedCall(call)) {\n const { to: target, value, data: callData } = call;\n const execution = createExecution({ target, value, callData });\n return execute({ execution });\n }\n }\n\n const executions = calls.map((call) => {\n if (isDelegatedCall(call)) {\n return processDelegatedCall(call);\n }\n const { to: target, value, data: callData } = call;\n return createExecution({ target, value, callData });\n });\n\n const mode =\n calls.length === 1\n ? ExecutionMode.SingleDefault\n : ExecutionMode.BatchDefault;\n return executeWithMode({ mode, executions });\n};\n\n/**\n * Encodes calls for execution by a DeleGator smart contract.\n *\n * @param caller - The address of the DeleGator contract.\n * @param calls - An array of Call objects, each containing 'to', optional 'data', and optional 'value'.\n * @returns A promise that resolves to the encoded function data as a hexadecimal string.\n * @description\n * - If there's a single call directly to the delegator, it returns the call data directly.\n * - For multiple calls or calls to other addresses, it creates executions and encodes them for the DeleGator's execute function.\n * - The execution mode is set to ExecutionMode.SingleDefault for a single call, or ExecutionMode.BatchDefault for multiple calls.\n *\n * todo: This doesn't fully expose the flexibility of the DeleGator's execute function, but it's a start.\n * maybe we add a mechanism where individual calls passed to this function can be encoded batches.\n */\nexport const encodeCallsForCaller = async (\n caller: Address,\n calls: readonly Call[],\n): Promise<Hex> => {\n if (calls.length === 1) {\n const call = calls[0];\n if (call && call.to === caller && !isDelegatedCall(call)) {\n // if there's a single call, and it's to the delegator, we can just return the calldata directly.\n return call.data ?? '0x';\n }\n }\n return encodeCalls(calls);\n};\n","import {\n parseAbiParameters,\n encodeAbiParameters,\n type Hex,\n encodePacked,\n keccak256,\n concat,\n hexToBytes,\n} from 'viem';\nimport { parseSignature } from 'webauthn-p256';\n\nexport const FIELD_MODULUS =\n 115792089210356248762697446949407573529996955224135760342422259061068512044369n;\nexport const MALLEABILITY_THRESHOLD = FIELD_MODULUS / 2n;\n\nexport const SIGNATURE_ABI_PARAMS = parseAbiParameters(\n 'bytes32, uint256, uint256, bytes, bool, string, string, uint256',\n);\n\n/**\n * This function is used to convert the client data returned from the\n * credentials API into a format that can be consumed by the DeleGator\n * contracts. We need the flattend JSON strings before and after the\n * userOpHash/challenge. This function provides those two client data string\n * slices.\n * @param clientDataJson - The client data JSON string.\n * @returns Returns [clientDataJSONPrefix and clientDataJSONSuffix]\n * ClientDataJSONPrefix contains the client data till the challengeHash\n * ClientDataJSONSuffix contains the client data after the challengeHash.\n */\nexport const splitOnChallenge = (\n clientDataJson: string,\n): [clientDataJSONPrefix: string, clientDataJSONSuffix: string] => {\n /*\n CientData looks like this:\n {\n \"type\": \"webauthn.create\" | \"webauthn.get\",\n \"challenge\": \"{userOpHash}\",\n \"origin\": \"{Domain}\",\n \"crossOrigin\": boolean\n }\n */\n try {\n const { challenge } = JSON.parse(clientDataJson);\n if (challenge === undefined) {\n throw new Error('No \"challenge\" found in the input string');\n }\n return clientDataJson.split(challenge) as [string, string];\n } catch (error) {\n throw new Error('No \"challenge\" found in the input string', {\n cause: error,\n });\n }\n};\n\n/**\n * Returns the index of '\"type\":' in the ClientData.\n * @param clientDataJson - Stringified ClientDataJSON.\n * @returns The index of '\"type\":' in the ClientData.\n */\nexport const getResponseTypeLocation = (clientDataJson: string): bigint => {\n try {\n // Find the index of the `\"type\":` key in the JSON string directly\n const typeIndex = clientDataJson.indexOf('\"type\":');\n\n if (typeIndex === -1) {\n throw new Error('No \"type\" found in the input string');\n }\n // Return the index of the `\"type\":` key\n return BigInt(typeIndex);\n } catch (error) {\n // Handle any errors that occur during the search\n throw new Error('No \"type\" found in the input string', {\n cause: error,\n });\n }\n};\n\n/**\n * Encodes a signature to a hexadecimal signature that will be accepted\n * by the DeleGator contracts.\n * @param keyId - The key used for the signature, represented as a hexadecimal string.\n * @param signature - The signature to convert, as Hex.\n * @param clientDataJSON - The client data used in the creation of the signature.\n * @param authenticatorData - The authenticator data used in the creation of the signature.\n * @returns The signature as a valid DeleGator signature encoded as Hexadecimal string.\n */\nexport function encodeDeleGatorSignature(\n keyId: string,\n signature: Hex,\n clientDataJSON: string,\n authenticatorData: Hex,\n): Hex {\n const keyIdHash = keccak256(encodePacked(['string'], [keyId]));\n\n const parsedSignature = parseSignature(signature);\n\n let { s } = parsedSignature;\n\n while (s > MALLEABILITY_THRESHOLD) {\n s = FIELD_MODULUS - s;\n }\n\n const { r } = parsedSignature;\n\n const [clientDataComponent1, clientDataComponent2] =\n splitOnChallenge(clientDataJSON);\n\n const { userVerified } = parseAuthenticatorFlags(authenticatorData);\n\n const responseTypeLocation = getResponseTypeLocation(clientDataJSON);\n\n const encodedSignature = encodeAbiParameters(SIGNATURE_ABI_PARAMS, [\n keyIdHash,\n r,\n s,\n authenticatorData,\n userVerified,\n clientDataComponent1,\n clientDataComponent2,\n responseTypeLocation,\n ]);\n return encodedSignature;\n}\n\nconst AUTHENTICATOR_DATA_FLAGS_OFFSET = 32;\n// We have all of the flag bits defined here for completeness, even though we only extract the userVerified flag.\nenum AuthenticatorDataFlagBitIndex {\n UserPresence = 0,\n UserVerified = 2,\n BackupEligibility = 3,\n BackupState = 4,\n AttestedCredentialData = 6,\n ExtensionData = 7,\n}\n\nexport type AuthenticatorFlags = {\n userVerified: boolean;\n};\n\n/**\n * Parses the authenticator data and returns an authenticator flags object with the `userVerified` flag.\n * See https://developer.mozilla.org/en-US/docs/Web/API/Web_Authentication_API/Authenticator_data.\n * @param authenticatorData - The authenticator data to parse.\n * @returns An object representing the parsed authenticator flags.\n */\nexport function parseAuthenticatorFlags(\n authenticatorData: Hex,\n): AuthenticatorFlags {\n const authenticatorDataBuffer = hexToBytes(authenticatorData);\n const dataBufferUint8 = new Uint8Array(authenticatorDataBuffer);\n const flags = dataBufferUint8[AUTHENTICATOR_DATA_FLAGS_OFFSET];\n if (flags === undefined) {\n throw new Error('Authenticator flags not found in authenticator data');\n }\n\n // Bit 0 is the least significant bit in the flags byte, so we left shift 0b1 by the bit index\n // eslint-disable-next-line no-bitwise\n const bitMask = 0b1 << AuthenticatorDataFlagBitIndex.UserVerified;\n\n return {\n // eslint-disable-next-line no-bitwise\n userVerified: (flags & bitMask) !== 0x0,\n };\n}\n\n/**\n * Creates a dummy signature.\n * This must meet all early-failure conditions of the real signature, but does not need to be a valid signature.\n * @param keyId - The key ID to use for the dummy signature.\n * @returns The encoded signature.\n */\nexport const createDummyWebAuthnSignature = (keyId: Hex) => {\n // https://developer.mozilla.org/en-US/docs/Web/API/Web_Authentication_API/Authenticator_data#data_structure\n const rpIdHash = keccak256(encodePacked(['string'], ['AuthenticatorData']));\n const flags = '0x05';\n const signCount = '0x00000000';\n const authenticatorData = concat([rpIdHash, flags, signCount]);\n\n const keyIdHash = keccak256(encodePacked(['string'], [keyId]));\n const rs =\n 57896044605178124381348723474703786764998477612067880171211129530534256022184n;\n const userVerification = true;\n const clientDataPrefix = '{\"type\":\"webauthn.get\",\"challenge\":\"';\n const clientDataSuffix = '\",\"origin\":\"passkey-domain\",\"crossOrigin\":false}';\n const responseTypeLocation = 1n;\n\n const encodedSignature = encodeAbiParameters(SIGNATURE_ABI_PARAMS, [\n keyIdHash,\n rs,\n rs,\n authenticatorData,\n userVerification,\n clientDataPrefix,\n clientDataSuffix,\n responseTypeLocation,\n ]);\n\n return encodedSignature;\n};\n"]}
|
|
1
|
+
{"version":3,"sources":["/home/runner/work/smart-accounts-kit/smart-accounts-kit/packages/smart-accounts-kit/dist/chunk-5ZBCTLQS.cjs","../src/constants.ts","../src/counterfactualAccountData.ts","../src/encodeCalls.ts","../src/webAuthn.ts"],"names":["Implementation","TransferWindow"],"mappings":"AAAA;AACE;AACA;AACA;AACA;AACA;AACA;AACF,wDAA6B;AAC7B;AACE;AACA;AACF,wDAA6B;AAC7B;AACA;ACTO,IAAK,eAAA,kBAAL,CAAA,CAAKA,eAAAA,EAAAA,GAAL;AACL,EAAAA,eAAAA,CAAA,UAAA,EAAA,EAAW,UAAA;AACX,EAAAA,eAAAA,CAAA,QAAA,EAAA,EAAS,QAAA;AACT,EAAAA,eAAAA,CAAA,eAAA,EAAA,EAAgB,eAAA;AAHN,EAAA,OAAAA,eAAAA;AAAA,CAAA,CAAA,CAAA,eAAA,GAAA,CAAA,CAAA,CAAA;AAoBL,IAAK,eAAA,kBAAL,CAAA,CAAKC,eAAAA,EAAAA,GAAL;AACL,EAAAA,eAAAA,CAAAA,eAAAA,CAAA,QAAA,EAAA,EAAS,IAAA,EAAA,EAAT,QAAA;AACA,EAAAA,eAAAA,CAAAA,eAAAA,CAAA,OAAA,EAAA,EAAQ,KAAA,EAAA,EAAR,OAAA;AACA,EAAAA,eAAAA,CAAAA,eAAAA,CAAA,QAAA,EAAA,EAAS,MAAA,EAAA,EAAT,QAAA;AACA,EAAAA,eAAAA,CAAAA,eAAAA,CAAA,UAAA,EAAA,EAAW,OAAA,EAAA,EAAX,UAAA;AACA,EAAAA,eAAAA,CAAAA,eAAAA,CAAA,SAAA,EAAA,EAAU,MAAA,EAAA,EAAV,SAAA;AACA,EAAAA,eAAAA,CAAAA,eAAAA,CAAA,WAAA,EAAA,EAAY,MAAA,EAAA,EAAZ,WAAA;AACA,EAAAA,eAAAA,CAAAA,eA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;AACE,MAAA;AAAqD,IAAA;AAGvD,IAAA;AAAuB,EAAA;AAGvB,IAAA;AAAuD,MAAA;AAC9C,IAAA;AACR,EAAA;AAEL;AAWO;AAML,EAAA;AAEA,EAAA;AAEA,EAAA;AAEA,EAAA;AACE,IAAA;AAAoB,EAAA;AAGtB,EAAA;AAEA,EAAA;AAGA,EAAA;AAEA,EAAA;AAEA,EAAA;AAAmE,IAAA;AACjE,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,EAAA;AAEF,EAAA;AACF;AAEA;AAqBO;AAGL,EAAA;AACA,EAAA;AACA,EAAA;AACA,EAAA;AACE,IAAA;AAAqE,EAAA;AAKvE,EAAA;AAEA,EAAA;AAAO;AAAA,IAAA;AAE+B,EAAA;AAExC;AAQO;AAEL,EAAA;AACA,EAAA;AACA,EAAA;AACA,EAAA;AAEA,EAAA;AACA,EAAA;AAEA,EAAA;AACA,EAAA;AACA,EAAA;AACA,EAAA;AAEA,EAAA;AAAmE,IAAA;AACjE,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,EAAA;AAGF,EAAA;AACF;AJ+DA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA","file":"/home/runner/work/smart-accounts-kit/smart-accounts-kit/packages/smart-accounts-kit/dist/chunk-5ZBCTLQS.cjs","sourcesContent":[null,"/**\n * To be used in sdk methods to call Implementation specific code\n * @type {Implementation}\n */\nexport enum Implementation {\n MultiSig = 'MultiSig',\n Hybrid = 'Hybrid',\n Stateless7702 = 'Stateless7702',\n}\n\n/**\n * Represents predefined time intervals (in seconds) for transfer windows.\n * These values are commonly used to specify the duration of transfer periods,\n * such as hourly, daily, weekly, etc., where each enum member's value is the\n * number of seconds in that interval.\n * @enum {number}\n * @property {number} Hourly - 1 hour (3600 seconds)\n * @property {number} Daily - 1 day (86400 seconds)\n * @property {number} Weekly - 1 week (604800 seconds)\n * @property {number} BiWeekly - 2 weeks (1209600 seconds)\n * @property {number} Monthly - 1 month (30 days, 2592000 seconds)\n * @property {number} Quarterly - 1 quarter (90 days, 7776000 seconds)\n * @property {number} Yearly - 1 year (365 days, 31536000 seconds)\n */\nexport enum TransferWindow {\n Hourly = 3600, // 60 * 60 (seconds)\n Daily = 86400, // 60 * 60 * 24 (seconds)\n Weekly = 604800, // 60 * 60 * 24 * 7 (seconds)\n BiWeekly = 1209600, // 60 * 60 * 24 * 14 (seconds)\n Monthly = 2592000, // 60 * 60 * 24 * 30 (seconds)\n Quarterly = 7776000, // 60 * 60 * 24 * 90 (seconds)\n Yearly = 31536000, // 60 * 60 * 24 * 365 (seconds)\n}\n","import type { Address, Hex } from 'viem';\nimport { getContractAddress, pad } from 'viem';\n\nimport { Implementation } from './constants';\nimport { initializeHybridDeleGator } from './DelegationFramework/HybridDeleGator/encode';\nimport { initializeMultiSigDeleGator } from './DelegationFramework/MultiSigDeleGator/encode';\nimport { create2Deploy as encodeCreate2Deploy } from './DelegationFramework/SimpleFactory/encode';\nimport { encodeProxyCreationCode } from './DelegationFramework/utils';\nimport type {\n SmartAccountsEnvironment,\n HybridDeleGatorDeployParams,\n MultiSigDeleGatorDeployParams,\n DeployParams,\n} from './types';\n\n/**\n * Infers counterfactual account data for a DeleGator smart account.\n *\n * @template TImplementation - The type of implementation, extending Implementation.\n * @template TDeployParams - The type of deployment parameters, defaults to DeployParams<Implementation>.\n * @param options - The options for generating counterfactual account data.\n * @param options.factory - The address of the SimpleFactory contract.\n * @param options.implementations - The DeleGator implementation contracts.\n * @param options.implementation - The implementation type to use.\n * @param options.deployParams - The deployment parameters for the specified implementation.\n * @param options.deploySalt - The salt to use for CREATE2 address computation.\n * @returns An object containing the counterfactual address and factory calldata.\n * @description This function calculates the address a DeleGator contract would have if deployed,\n * and provides the calldata needed to deploy it.\n */\nexport const getCounterfactualAccountData = async <\n TImplementation extends Implementation,\n>({\n factory,\n implementations,\n implementation,\n deployParams,\n deploySalt,\n}: {\n factory: Address;\n implementations: SmartAccountsEnvironment['implementations'];\n implementation: TImplementation;\n deployParams: DeployParams<TImplementation>;\n deploySalt: Hex;\n}): Promise<{ factoryData: Hex; address: Address }> => {\n let implementationAddress: Address;\n let initcode: Hex;\n\n switch (implementation) {\n case Implementation.Hybrid: {\n const [owner, keyIds, xValues, yValues] =\n deployParams as HybridDeleGatorDeployParams;\n\n if (!implementations.HybridDeleGatorImpl) {\n throw new Error(\n 'HybridDeleGatorImpl address not provided in environment',\n );\n }\n\n implementationAddress = implementations.HybridDeleGatorImpl;\n\n const p256Owners = keyIds.map((keyId, index) => {\n const xValue = xValues[index];\n const yValue = yValues[index];\n\n if (!xValue || !yValue) {\n throw new Error(\n `Missing X or Y value for keyId ${keyId} at index ${index}`,\n );\n }\n\n return {\n keyId,\n x: xValue,\n y: yValue,\n };\n });\n\n initcode = initializeHybridDeleGator({ eoaOwner: owner, p256Owners });\n break;\n }\n case Implementation.MultiSig: {\n const [owners, threshold] = deployParams as MultiSigDeleGatorDeployParams;\n\n if (!implementations.MultiSigDeleGatorImpl) {\n throw new Error(\n 'MultiSigDeleGatorImpl address not provided in environment',\n );\n }\n\n implementationAddress = implementations.MultiSigDeleGatorImpl;\n initcode = initializeMultiSigDeleGator({ owners, threshold });\n break;\n }\n default:\n throw new Error(`Implementation type '${implementation}' not supported`);\n }\n\n const salt = pad(deploySalt, { dir: 'left', size: 32 });\n\n const proxyCreationCode = encodeProxyCreationCode({\n implementationAddress,\n initcode,\n });\n\n const address = getContractAddress({\n bytecode: proxyCreationCode,\n from: factory,\n opcode: 'CREATE2',\n salt,\n });\n\n const factoryData = encodeCreate2Deploy(proxyCreationCode, salt);\n\n return {\n factoryData,\n address,\n };\n};\n","import { DelegationManager } from '@metamask/delegation-abis';\nimport { encodeFunctionData } from 'viem';\nimport type { Address, Hex } from 'viem';\n\nimport type { DelegatedCall } from './actions/erc7710RedeemDelegationAction';\nimport {\n execute,\n executeWithMode,\n} from './DelegationFramework/DeleGatorCore/encode';\nimport {\n ExecutionMode,\n createExecution,\n encodeExecutionCalldatas,\n} from './executions';\nimport type { Call } from './types';\n\n/**\n * Checks if a call is a delegated call by checking for the presence of permissionsContext and delegationManager.\n *\n * @param call - The call to check.\n * @returns True if the call is a delegated call, false otherwise.\n */\nconst isDelegatedCall = (call: Call): call is DelegatedCall => {\n return 'permissionsContext' in call && 'delegationManager' in call;\n};\n\n/**\n * If there's a single call with permissionsContext and delegationManager,\n * processes it as a delegated call.\n *\n * @param call - The call to process.\n * @returns The execution object for the delegated call.\n * @description\n * This function creates an execution that calls redeemDelegations on the delegation manager.\n */\nconst processDelegatedCall = (call: DelegatedCall) => {\n const {\n permissionsContext,\n delegationManager,\n to: target,\n value,\n data: callData,\n } = call;\n\n const callAsExecution = createExecution({ target, value, callData });\n\n if (!permissionsContext) {\n return callAsExecution;\n }\n\n const redeemCalldata = encodeFunctionData({\n abi: DelegationManager.abi,\n functionName: 'redeemDelegations',\n args: [\n [permissionsContext],\n [ExecutionMode.SingleDefault],\n encodeExecutionCalldatas([[callAsExecution]]),\n ],\n });\n\n return createExecution({\n target: delegationManager,\n callData: redeemCalldata,\n });\n};\n\n/**\n * If there's a single call, encode the shorthand `execute` function. Otherwise, encode the `executeWithMode` function. Execution type will always be \"default\".\n *\n * @param calls - The calls to execute.\n * @returns The encoded calldata for the DeleGator to execute the calls.\n * @description\n * This function supports both single and batch execution modes.\n * For single calls, it uses the gas-efficient execute function.\n */\nexport const encodeCalls = (calls: readonly Call[]) => {\n if (calls.length === 1) {\n const call = calls[0];\n if (call && !isDelegatedCall(call)) {\n const { to: target, value, data: callData } = call;\n const execution = createExecution({ target, value, callData });\n return execute({ execution });\n }\n }\n\n const executions = calls.map((call) => {\n if (isDelegatedCall(call)) {\n return processDelegatedCall(call);\n }\n const { to: target, value, data: callData } = call;\n return createExecution({ target, value, callData });\n });\n\n const mode =\n calls.length === 1\n ? ExecutionMode.SingleDefault\n : ExecutionMode.BatchDefault;\n return executeWithMode({ mode, executions });\n};\n\n/**\n * Encodes calls for execution by a DeleGator smart contract.\n *\n * @param caller - The address of the DeleGator contract.\n * @param calls - An array of Call objects, each containing 'to', optional 'data', and optional 'value'.\n * @returns A promise that resolves to the encoded function data as a hexadecimal string.\n * @description\n * - If there's a single call directly to the delegator, it returns the call data directly.\n * - For multiple calls or calls to other addresses, it creates executions and encodes them for the DeleGator's execute function.\n * - The execution mode is set to ExecutionMode.SingleDefault for a single call, or ExecutionMode.BatchDefault for multiple calls.\n *\n * todo: This doesn't fully expose the flexibility of the DeleGator's execute function, but it's a start.\n * maybe we add a mechanism where individual calls passed to this function can be encoded batches.\n */\nexport const encodeCallsForCaller = async (\n caller: Address,\n calls: readonly Call[],\n): Promise<Hex> => {\n if (calls.length === 1) {\n const call = calls[0];\n if (call && call.to === caller && !isDelegatedCall(call)) {\n // if there's a single call, and it's to the delegator, we can just return the calldata directly.\n return call.data ?? '0x';\n }\n }\n return encodeCalls(calls);\n};\n","import {\n parseAbiParameters,\n encodeAbiParameters,\n type Hex,\n encodePacked,\n keccak256,\n concat,\n hexToBytes,\n} from 'viem';\nimport { parseSignature } from 'webauthn-p256';\n\nexport const FIELD_MODULUS =\n 115792089210356248762697446949407573529996955224135760342422259061068512044369n;\nexport const MALLEABILITY_THRESHOLD = FIELD_MODULUS / 2n;\n\nexport const SIGNATURE_ABI_PARAMS = parseAbiParameters(\n 'bytes32, uint256, uint256, bytes, bool, string, string, uint256',\n);\n\n/**\n * This function is used to convert the client data returned from the\n * credentials API into a format that can be consumed by the DeleGator\n * contracts. We need the flattend JSON strings before and after the\n * userOpHash/challenge. This function provides those two client data string\n * slices.\n * @param clientDataJson - The client data JSON string.\n * @returns Returns [clientDataJSONPrefix and clientDataJSONSuffix]\n * ClientDataJSONPrefix contains the client data till the challengeHash\n * ClientDataJSONSuffix contains the client data after the challengeHash.\n */\nexport const splitOnChallenge = (\n clientDataJson: string,\n): [clientDataJSONPrefix: string, clientDataJSONSuffix: string] => {\n /*\n CientData looks like this:\n {\n \"type\": \"webauthn.create\" | \"webauthn.get\",\n \"challenge\": \"{userOpHash}\",\n \"origin\": \"{Domain}\",\n \"crossOrigin\": boolean\n }\n */\n try {\n const { challenge } = JSON.parse(clientDataJson);\n if (challenge === undefined) {\n throw new Error('No \"challenge\" found in the input string');\n }\n return clientDataJson.split(challenge) as [string, string];\n } catch (error) {\n throw new Error('No \"challenge\" found in the input string', {\n cause: error,\n });\n }\n};\n\n/**\n * Returns the index of '\"type\":' in the ClientData.\n * @param clientDataJson - Stringified ClientDataJSON.\n * @returns The index of '\"type\":' in the ClientData.\n */\nexport const getResponseTypeLocation = (clientDataJson: string): bigint => {\n try {\n // Find the index of the `\"type\":` key in the JSON string directly\n const typeIndex = clientDataJson.indexOf('\"type\":');\n\n if (typeIndex === -1) {\n throw new Error('No \"type\" found in the input string');\n }\n // Return the index of the `\"type\":` key\n return BigInt(typeIndex);\n } catch (error) {\n // Handle any errors that occur during the search\n throw new Error('No \"type\" found in the input string', {\n cause: error,\n });\n }\n};\n\n/**\n * Encodes a signature to a hexadecimal signature that will be accepted\n * by the DeleGator contracts.\n * @param keyId - The key used for the signature, represented as a hexadecimal string.\n * @param signature - The signature to convert, as Hex.\n * @param clientDataJSON - The client data used in the creation of the signature.\n * @param authenticatorData - The authenticator data used in the creation of the signature.\n * @returns The signature as a valid DeleGator signature encoded as Hexadecimal string.\n */\nexport function encodeDeleGatorSignature(\n keyId: string,\n signature: Hex,\n clientDataJSON: string,\n authenticatorData: Hex,\n): Hex {\n const keyIdHash = keccak256(encodePacked(['string'], [keyId]));\n\n const parsedSignature = parseSignature(signature);\n\n let { s } = parsedSignature;\n\n while (s > MALLEABILITY_THRESHOLD) {\n s = FIELD_MODULUS - s;\n }\n\n const { r } = parsedSignature;\n\n const [clientDataComponent1, clientDataComponent2] =\n splitOnChallenge(clientDataJSON);\n\n const { userVerified } = parseAuthenticatorFlags(authenticatorData);\n\n const responseTypeLocation = getResponseTypeLocation(clientDataJSON);\n\n const encodedSignature = encodeAbiParameters(SIGNATURE_ABI_PARAMS, [\n keyIdHash,\n r,\n s,\n authenticatorData,\n userVerified,\n clientDataComponent1,\n clientDataComponent2,\n responseTypeLocation,\n ]);\n return encodedSignature;\n}\n\nconst AUTHENTICATOR_DATA_FLAGS_OFFSET = 32;\n// We have all of the flag bits defined here for completeness, even though we only extract the userVerified flag.\nenum AuthenticatorDataFlagBitIndex {\n UserPresence = 0,\n UserVerified = 2,\n BackupEligibility = 3,\n BackupState = 4,\n AttestedCredentialData = 6,\n ExtensionData = 7,\n}\n\nexport type AuthenticatorFlags = {\n userVerified: boolean;\n};\n\n/**\n * Parses the authenticator data and returns an authenticator flags object with the `userVerified` flag.\n * See https://developer.mozilla.org/en-US/docs/Web/API/Web_Authentication_API/Authenticator_data.\n * @param authenticatorData - The authenticator data to parse.\n * @returns An object representing the parsed authenticator flags.\n */\nexport function parseAuthenticatorFlags(\n authenticatorData: Hex,\n): AuthenticatorFlags {\n const authenticatorDataBuffer = hexToBytes(authenticatorData);\n const dataBufferUint8 = new Uint8Array(authenticatorDataBuffer);\n const flags = dataBufferUint8[AUTHENTICATOR_DATA_FLAGS_OFFSET];\n if (flags === undefined) {\n throw new Error('Authenticator flags not found in authenticator data');\n }\n\n // Bit 0 is the least significant bit in the flags byte, so we left shift 0b1 by the bit index\n // eslint-disable-next-line no-bitwise\n const bitMask = 0b1 << AuthenticatorDataFlagBitIndex.UserVerified;\n\n return {\n // eslint-disable-next-line no-bitwise\n userVerified: (flags & bitMask) !== 0x0,\n };\n}\n\n/**\n * Creates a dummy signature.\n * This must meet all early-failure conditions of the real signature, but does not need to be a valid signature.\n * @param keyId - The key ID to use for the dummy signature.\n * @returns The encoded signature.\n */\nexport const createDummyWebAuthnSignature = (keyId: Hex) => {\n // https://developer.mozilla.org/en-US/docs/Web/API/Web_Authentication_API/Authenticator_data#data_structure\n const rpIdHash = keccak256(encodePacked(['string'], ['AuthenticatorData']));\n const flags = '0x05';\n const signCount = '0x00000000';\n const authenticatorData = concat([rpIdHash, flags, signCount]);\n\n const keyIdHash = keccak256(encodePacked(['string'], [keyId]));\n const rs =\n 57896044605178124381348723474703786764998477612067880171211129530534256022184n;\n const userVerification = true;\n const clientDataPrefix = '{\"type\":\"webauthn.get\",\"challenge\":\"';\n const clientDataSuffix = '\",\"origin\":\"passkey-domain\",\"crossOrigin\":false}';\n const responseTypeLocation = 1n;\n\n const encodedSignature = encodeAbiParameters(SIGNATURE_ABI_PARAMS, [\n keyIdHash,\n rs,\n rs,\n authenticatorData,\n userVerification,\n clientDataPrefix,\n clientDataSuffix,\n responseTypeLocation,\n ]);\n\n return encodedSignature;\n};\n"]}
|
|
@@ -4,7 +4,7 @@ import {
|
|
|
4
4
|
import {
|
|
5
5
|
__export,
|
|
6
6
|
toDelegationStruct
|
|
7
|
-
} from "./chunk-
|
|
7
|
+
} from "./chunk-BJGZGTRU.mjs";
|
|
8
8
|
|
|
9
9
|
// src/DelegationFramework/utils.ts
|
|
10
10
|
import { ERC1967Proxy } from "@metamask/delegation-abis";
|
|
@@ -828,4 +828,4 @@ export {
|
|
|
828
828
|
execute6,
|
|
829
829
|
encode_exports4
|
|
830
830
|
};
|
|
831
|
-
//# sourceMappingURL=chunk-
|
|
831
|
+
//# sourceMappingURL=chunk-72UQFUL5.mjs.map
|
|
@@ -1068,7 +1068,8 @@ function createFunctionCallCaveatBuilder(environment, config) {
|
|
|
1068
1068
|
"Cannot specify both allowedCalldata and exactCalldata. Please use only one calldata restriction type."
|
|
1069
1069
|
);
|
|
1070
1070
|
}
|
|
1071
|
-
const
|
|
1071
|
+
const valueLteConfig = config.valueLte ?? { maxValue: 0n };
|
|
1072
|
+
const caveatBuilder = createCaveatBuilder(environment).addCaveat("allowedTargets", { targets }).addCaveat("allowedMethods", { selectors }).addCaveat("valueLte", valueLteConfig);
|
|
1072
1073
|
if (allowedCalldata2 && allowedCalldata2.length > 0) {
|
|
1073
1074
|
allowedCalldata2.forEach((calldataConfig) => {
|
|
1074
1075
|
caveatBuilder.addCaveat("allowedCalldata", calldataConfig);
|
|
@@ -1459,4 +1460,4 @@ export {
|
|
|
1459
1460
|
prepareSignDelegationTypedData,
|
|
1460
1461
|
signDelegation
|
|
1461
1462
|
};
|
|
1462
|
-
//# sourceMappingURL=chunk-
|
|
1463
|
+
//# sourceMappingURL=chunk-BJGZGTRU.mjs.map
|