@metamask/smart-accounts-kit 1.3.0 → 1.5.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 +20 -1
- package/dist/actions/index.cjs +8 -4
- package/dist/actions/index.cjs.map +1 -1
- package/dist/actions/index.d.cts +4 -2
- package/dist/actions/index.d.ts +4 -2
- package/dist/actions/index.mjs +7 -3
- package/dist/{caveats-Cey0wm33.d.cts → caveats-CaSt_VHs.d.cts} +1 -1
- package/dist/{caveats-CQbtzOKm.d.ts → caveats-DQ6HoAHe.d.ts} +1 -1
- package/dist/{chunk-GZ7HHI2D.cjs → chunk-7FYDQNJ3.cjs} +12 -12
- package/dist/{chunk-GZ7HHI2D.cjs.map → chunk-7FYDQNJ3.cjs.map} +1 -1
- package/dist/{chunk-FKI4OME5.mjs → chunk-BGOSYTKV.mjs} +254 -60
- package/dist/chunk-BGOSYTKV.mjs.map +1 -0
- package/dist/{chunk-57I2FJY7.cjs → chunk-DN4O5VOP.cjs} +102 -102
- package/dist/{chunk-57I2FJY7.cjs.map → chunk-DN4O5VOP.cjs.map} +1 -1
- package/dist/{chunk-DLCTHNAE.cjs → chunk-FH6HZCHI.cjs} +11 -11
- package/dist/{chunk-DLCTHNAE.cjs.map → chunk-FH6HZCHI.cjs.map} +1 -1
- package/dist/{chunk-SZOX7K2V.cjs → chunk-IBZSNB7D.cjs} +81 -33
- package/dist/chunk-IBZSNB7D.cjs.map +1 -0
- package/dist/{chunk-Z4D7ZWVB.mjs → chunk-MV2KHN75.mjs} +84 -36
- package/dist/chunk-MV2KHN75.mjs.map +1 -0
- package/dist/{chunk-AC2BQSYP.mjs → chunk-N66VAWMO.mjs} +2 -2
- package/dist/{chunk-3PBVHNYP.cjs → chunk-SCS3CFRE.cjs} +10 -10
- package/dist/{chunk-3PBVHNYP.cjs.map → chunk-SCS3CFRE.cjs.map} +1 -1
- package/dist/{chunk-26PADMXR.mjs → chunk-TBHT26BV.mjs} +4 -4
- package/dist/{chunk-KBSFVKUB.mjs → chunk-W7O2UQL5.mjs} +2 -2
- package/dist/{chunk-AJWMPR7X.cjs → chunk-XEOE25DE.cjs} +298 -104
- package/dist/chunk-XEOE25DE.cjs.map +1 -0
- package/dist/{chunk-LQXOM3TA.mjs → chunk-YXHUT56Z.mjs} +3 -3
- package/dist/contracts/index.cjs +5 -5
- package/dist/contracts/index.d.cts +3 -2
- package/dist/contracts/index.d.ts +3 -2
- package/dist/contracts/index.mjs +4 -4
- package/dist/delegation-BKkEyxZY.d.cts +64 -0
- package/dist/delegation-DbPGWKfP.d.ts +64 -0
- package/dist/experimental/index.cjs +7 -7
- package/dist/experimental/index.mjs +1 -1
- package/dist/{index-D2THBlfm.d.ts → index-DXdlz7t4.d.ts} +2 -1
- package/dist/{index-BDC55AA9.d.cts → index-DfDAuvr5.d.cts} +58 -5
- package/dist/{index-DhG2lH80.d.ts → index-G78z6nwi.d.ts} +58 -5
- package/dist/{index-DE87r5KY.d.cts → index-yU3olCJV.d.cts} +2 -1
- package/dist/index.cjs +22 -20
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +7 -6
- package/dist/index.d.ts +7 -6
- package/dist/index.mjs +9 -7
- package/dist/index.mjs.map +1 -1
- package/dist/{delegation-Bx4FEAIU.d.ts → resolveCaveats-DiqGB-T5.d.cts} +4 -57
- package/dist/{delegation-KbWHzRxV.d.cts → resolveCaveats-s2snaFEo.d.ts} +4 -57
- package/dist/utils/index.cjs +4 -4
- package/dist/utils/index.d.cts +3 -2
- package/dist/utils/index.d.ts +3 -2
- package/dist/utils/index.mjs +3 -3
- package/package.json +4 -4
- package/dist/chunk-AJWMPR7X.cjs.map +0 -1
- package/dist/chunk-FKI4OME5.mjs.map +0 -1
- package/dist/chunk-SZOX7K2V.cjs.map +0 -1
- package/dist/chunk-Z4D7ZWVB.mjs.map +0 -1
- /package/dist/{chunk-AC2BQSYP.mjs.map → chunk-N66VAWMO.mjs.map} +0 -0
- /package/dist/{chunk-26PADMXR.mjs.map → chunk-TBHT26BV.mjs.map} +0 -0
- /package/dist/{chunk-KBSFVKUB.mjs.map → chunk-W7O2UQL5.mjs.map} +0 -0
- /package/dist/{chunk-LQXOM3TA.mjs.map → chunk-YXHUT56Z.mjs.map} +0 -0
|
@@ -135,13 +135,6 @@ var CaveatBuilder = class _CaveatBuilder {
|
|
|
135
135
|
}
|
|
136
136
|
};
|
|
137
137
|
|
|
138
|
-
// src/caveatBuilder/types.ts
|
|
139
|
-
var BalanceChangeType = /* @__PURE__ */ ((BalanceChangeType2) => {
|
|
140
|
-
BalanceChangeType2[BalanceChangeType2["Increase"] = 0] = "Increase";
|
|
141
|
-
BalanceChangeType2[BalanceChangeType2["Decrease"] = 1] = "Decrease";
|
|
142
|
-
return BalanceChangeType2;
|
|
143
|
-
})(BalanceChangeType || {});
|
|
144
|
-
|
|
145
138
|
// src/caveatBuilder/allowedCalldataBuilder.ts
|
|
146
139
|
import { createAllowedCalldataTerms } from "@metamask/delegation-core";
|
|
147
140
|
var allowedCalldata = "allowedCalldata";
|
|
@@ -318,7 +311,10 @@ var deployedBuilder = (environment, config) => {
|
|
|
318
311
|
};
|
|
319
312
|
|
|
320
313
|
// src/caveatBuilder/erc1155BalanceChangeBuilder.ts
|
|
321
|
-
import {
|
|
314
|
+
import {
|
|
315
|
+
createERC1155BalanceChangeTerms,
|
|
316
|
+
BalanceChangeType
|
|
317
|
+
} from "@metamask/delegation-core";
|
|
322
318
|
import { isAddress as isAddress3 } from "viem";
|
|
323
319
|
var erc1155BalanceChange = "erc1155BalanceChange";
|
|
324
320
|
var erc1155BalanceChangeBuilder = (environment, config) => {
|
|
@@ -335,7 +331,7 @@ var erc1155BalanceChangeBuilder = (environment, config) => {
|
|
|
335
331
|
if (tokenId < 0n) {
|
|
336
332
|
throw new Error("Invalid tokenId: must be a non-negative number");
|
|
337
333
|
}
|
|
338
|
-
if (changeType !==
|
|
334
|
+
if (changeType !== BalanceChangeType.Increase && changeType !== BalanceChangeType.Decrease) {
|
|
339
335
|
throw new Error("Invalid changeType: must be either Increase or Decrease");
|
|
340
336
|
}
|
|
341
337
|
const terms = createERC1155BalanceChangeTerms({
|
|
@@ -359,7 +355,10 @@ var erc1155BalanceChangeBuilder = (environment, config) => {
|
|
|
359
355
|
};
|
|
360
356
|
|
|
361
357
|
// src/caveatBuilder/erc20BalanceChangeBuilder.ts
|
|
362
|
-
import {
|
|
358
|
+
import {
|
|
359
|
+
createERC20BalanceChangeTerms,
|
|
360
|
+
BalanceChangeType as BalanceChangeType2
|
|
361
|
+
} from "@metamask/delegation-core";
|
|
363
362
|
import { isAddress as isAddress4 } from "viem";
|
|
364
363
|
var erc20BalanceChange = "erc20BalanceChange";
|
|
365
364
|
var erc20BalanceChangeBuilder = (environment, config) => {
|
|
@@ -370,7 +369,7 @@ var erc20BalanceChangeBuilder = (environment, config) => {
|
|
|
370
369
|
if (balance <= 0n) {
|
|
371
370
|
throw new Error("Invalid balance: must be a positive number");
|
|
372
371
|
}
|
|
373
|
-
if (changeType !==
|
|
372
|
+
if (changeType !== BalanceChangeType2.Increase && changeType !== BalanceChangeType2.Decrease) {
|
|
374
373
|
throw new Error("Invalid changeType: must be either Increase or Decrease");
|
|
375
374
|
}
|
|
376
375
|
const terms = createERC20BalanceChangeTerms({
|
|
@@ -468,7 +467,10 @@ var erc20TransferAmountBuilder = (environment, config) => {
|
|
|
468
467
|
};
|
|
469
468
|
|
|
470
469
|
// src/caveatBuilder/erc721BalanceChangeBuilder.ts
|
|
471
|
-
import {
|
|
470
|
+
import {
|
|
471
|
+
createERC721BalanceChangeTerms,
|
|
472
|
+
BalanceChangeType as BalanceChangeType3
|
|
473
|
+
} from "@metamask/delegation-core";
|
|
472
474
|
import { isAddress as isAddress6 } from "viem";
|
|
473
475
|
var erc721BalanceChange = "erc721BalanceChange";
|
|
474
476
|
var erc721BalanceChangeBuilder = (environment, config) => {
|
|
@@ -482,7 +484,7 @@ var erc721BalanceChangeBuilder = (environment, config) => {
|
|
|
482
484
|
if (amount <= 0n) {
|
|
483
485
|
throw new Error("Invalid balance: must be a positive number");
|
|
484
486
|
}
|
|
485
|
-
if (changeType !==
|
|
487
|
+
if (changeType !== BalanceChangeType3.Increase && changeType !== BalanceChangeType3.Decrease) {
|
|
486
488
|
throw new Error("Invalid changeType: must be either Increase or Decrease");
|
|
487
489
|
}
|
|
488
490
|
const terms = createERC721BalanceChangeTerms({
|
|
@@ -750,7 +752,10 @@ var multiTokenPeriodBuilder = (environment, config) => {
|
|
|
750
752
|
};
|
|
751
753
|
|
|
752
754
|
// src/caveatBuilder/nativeBalanceChangeBuilder.ts
|
|
753
|
-
import {
|
|
755
|
+
import {
|
|
756
|
+
createNativeBalanceChangeTerms,
|
|
757
|
+
BalanceChangeType as BalanceChangeType4
|
|
758
|
+
} from "@metamask/delegation-core";
|
|
754
759
|
import { isAddress as isAddress12 } from "viem";
|
|
755
760
|
var nativeBalanceChange = "nativeBalanceChange";
|
|
756
761
|
var nativeBalanceChangeBuilder = (environment, config) => {
|
|
@@ -761,7 +766,7 @@ var nativeBalanceChangeBuilder = (environment, config) => {
|
|
|
761
766
|
if (balance <= 0n) {
|
|
762
767
|
throw new Error("Invalid balance: must be a positive number");
|
|
763
768
|
}
|
|
764
|
-
if (changeType !==
|
|
769
|
+
if (changeType !== BalanceChangeType4.Increase && changeType !== BalanceChangeType4.Decrease) {
|
|
765
770
|
throw new Error("Invalid changeType: must be either Increase or Decrease");
|
|
766
771
|
}
|
|
767
772
|
const terms = createNativeBalanceChangeTerms({
|
|
@@ -1327,9 +1332,15 @@ var createCaveatBuilderFromScope = (environment, scopeConfig) => {
|
|
|
1327
1332
|
var resolveCaveats = ({
|
|
1328
1333
|
environment,
|
|
1329
1334
|
scope,
|
|
1330
|
-
caveats
|
|
1335
|
+
caveats,
|
|
1336
|
+
isScopeOptional
|
|
1331
1337
|
}) => {
|
|
1332
|
-
|
|
1338
|
+
if (!scope && !isScopeOptional) {
|
|
1339
|
+
throw new Error("Scope is required");
|
|
1340
|
+
}
|
|
1341
|
+
const scopeCaveatBuilder = scope ? createCaveatBuilderFromScope(environment, scope) : createCaveatBuilder(environment, {
|
|
1342
|
+
allowInsecureUnrestrictedDelegation: true
|
|
1343
|
+
});
|
|
1333
1344
|
if (caveats) {
|
|
1334
1345
|
if ("build" in caveats && typeof caveats.build === "function") {
|
|
1335
1346
|
caveats.build().forEach((caveat) => {
|
|
@@ -1688,7 +1699,7 @@ var Sender = class {
|
|
|
1688
1699
|
};
|
|
1689
1700
|
|
|
1690
1701
|
// package.json
|
|
1691
|
-
var version = "1.
|
|
1702
|
+
var version = "1.5.0";
|
|
1692
1703
|
|
|
1693
1704
|
// src/analytics/index.ts
|
|
1694
1705
|
function isCompleteBase(value) {
|
|
@@ -1938,14 +1949,16 @@ var hashDelegation = (input) => {
|
|
|
1938
1949
|
const delegationStruct = toDelegationStruct(input);
|
|
1939
1950
|
return hashDelegationCore(delegationStruct);
|
|
1940
1951
|
};
|
|
1941
|
-
var
|
|
1942
|
-
|
|
1943
|
-
|
|
1952
|
+
var extractLeafDelegation = (permissionContext) => {
|
|
1953
|
+
const delegations = decodeDelegations(permissionContext);
|
|
1954
|
+
if (delegations.length === 0) {
|
|
1955
|
+
throw new Error("Permission context must contain at least one delegation");
|
|
1944
1956
|
}
|
|
1945
|
-
|
|
1946
|
-
|
|
1957
|
+
const leafDelegation = delegations[0];
|
|
1958
|
+
if (!leafDelegation) {
|
|
1959
|
+
throw new Error("Failed to extract leaf delegation");
|
|
1947
1960
|
}
|
|
1948
|
-
return
|
|
1961
|
+
return leafDelegation;
|
|
1949
1962
|
};
|
|
1950
1963
|
var getCaveatNames = ({
|
|
1951
1964
|
caveats,
|
|
@@ -1965,11 +1978,47 @@ var getCaveatNames = ({
|
|
|
1965
1978
|
}
|
|
1966
1979
|
return [];
|
|
1967
1980
|
};
|
|
1981
|
+
var resolveDelegationArgs = (options) => {
|
|
1982
|
+
const optionsHasParentPermissionContext = "parentPermissionContext" in options && options.parentPermissionContext;
|
|
1983
|
+
const resolvedParentDelegation = optionsHasParentPermissionContext ? extractLeafDelegation(options.parentPermissionContext) : options.parentDelegation;
|
|
1984
|
+
const authority = (() => {
|
|
1985
|
+
if (!resolvedParentDelegation) {
|
|
1986
|
+
if (!options.scope) {
|
|
1987
|
+
throw new Error(
|
|
1988
|
+
"Invalid arguments - must specify either parentDelegation, parentPermissionContext, or scope"
|
|
1989
|
+
);
|
|
1990
|
+
}
|
|
1991
|
+
return ROOT_AUTHORITY;
|
|
1992
|
+
}
|
|
1993
|
+
if (typeof resolvedParentDelegation === "string") {
|
|
1994
|
+
if (resolvedParentDelegation.toLowerCase() === ROOT_AUTHORITY.toLowerCase()) {
|
|
1995
|
+
throw new Error(
|
|
1996
|
+
`Invalid parent delegation - cannot be ${ROOT_AUTHORITY}`
|
|
1997
|
+
);
|
|
1998
|
+
}
|
|
1999
|
+
return resolvedParentDelegation;
|
|
2000
|
+
}
|
|
2001
|
+
return hashDelegation(resolvedParentDelegation);
|
|
2002
|
+
})();
|
|
2003
|
+
const hasInheritance = resolvedParentDelegation !== void 0;
|
|
2004
|
+
const caveats = resolveCaveats({
|
|
2005
|
+
environment: options.environment,
|
|
2006
|
+
scope: options.scope,
|
|
2007
|
+
caveats: options.caveats,
|
|
2008
|
+
isScopeOptional: hasInheritance
|
|
2009
|
+
});
|
|
2010
|
+
return {
|
|
2011
|
+
authority,
|
|
2012
|
+
caveats,
|
|
2013
|
+
hasInheritance,
|
|
2014
|
+
salt: options.salt ?? "0x00"
|
|
2015
|
+
};
|
|
2016
|
+
};
|
|
1968
2017
|
var createDelegation = (options) => {
|
|
1969
|
-
const caveats =
|
|
2018
|
+
const { authority, caveats, hasInheritance, salt } = resolveDelegationArgs(options);
|
|
1970
2019
|
trackSmartAccountsKitFunctionCall("createDelegation", {
|
|
1971
|
-
|
|
1972
|
-
scope: options.scope
|
|
2020
|
+
hasInheritance,
|
|
2021
|
+
scope: options.scope?.type ?? null,
|
|
1973
2022
|
caveatNames: getCaveatNames({
|
|
1974
2023
|
caveats,
|
|
1975
2024
|
environment: options.environment
|
|
@@ -1978,17 +2027,17 @@ var createDelegation = (options) => {
|
|
|
1978
2027
|
return {
|
|
1979
2028
|
delegate: options.to,
|
|
1980
2029
|
delegator: options.from,
|
|
1981
|
-
authority
|
|
2030
|
+
authority,
|
|
1982
2031
|
caveats,
|
|
1983
|
-
salt
|
|
2032
|
+
salt,
|
|
1984
2033
|
signature: "0x"
|
|
1985
2034
|
};
|
|
1986
2035
|
};
|
|
1987
2036
|
var createOpenDelegation = (options) => {
|
|
1988
|
-
const caveats =
|
|
2037
|
+
const { authority, caveats, hasInheritance, salt } = resolveDelegationArgs(options);
|
|
1989
2038
|
trackSmartAccountsKitFunctionCall("createOpenDelegation", {
|
|
1990
|
-
|
|
1991
|
-
scope: options.scope
|
|
2039
|
+
hasInheritance,
|
|
2040
|
+
scope: options.scope?.type ?? null,
|
|
1992
2041
|
caveatNames: getCaveatNames({
|
|
1993
2042
|
caveats,
|
|
1994
2043
|
environment: options.environment
|
|
@@ -1997,9 +2046,9 @@ var createOpenDelegation = (options) => {
|
|
|
1997
2046
|
return {
|
|
1998
2047
|
delegate: ANY_BENEFICIARY,
|
|
1999
2048
|
delegator: options.from,
|
|
2000
|
-
authority
|
|
2049
|
+
authority,
|
|
2001
2050
|
caveats,
|
|
2002
|
-
salt
|
|
2051
|
+
salt,
|
|
2003
2052
|
signature: "0x"
|
|
2004
2053
|
};
|
|
2005
2054
|
};
|
|
@@ -2063,7 +2112,6 @@ export {
|
|
|
2063
2112
|
ScopeType,
|
|
2064
2113
|
CaveatType,
|
|
2065
2114
|
CaveatBuilder,
|
|
2066
|
-
BalanceChangeType,
|
|
2067
2115
|
createCaveatBuilder,
|
|
2068
2116
|
isDefined,
|
|
2069
2117
|
toHexOrThrow,
|
|
@@ -2088,4 +2136,4 @@ export {
|
|
|
2088
2136
|
prepareSignDelegationTypedData,
|
|
2089
2137
|
signDelegation
|
|
2090
2138
|
};
|
|
2091
|
-
//# sourceMappingURL=chunk-
|
|
2139
|
+
//# sourceMappingURL=chunk-MV2KHN75.mjs.map
|