@rhinestone/sdk 1.4.1 → 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/README.md +89 -1
- package/dist/src/accounts/index.d.ts +1 -0
- package/dist/src/accounts/index.d.ts.map +1 -1
- package/dist/src/accounts/index.js +8 -2
- package/dist/src/accounts/json-rpc/providers.js +1 -1
- package/dist/src/accounts/signing/common.d.ts +8 -2
- package/dist/src/accounts/signing/common.d.ts.map +1 -1
- package/dist/src/auth/provider.d.ts +7 -0
- package/dist/src/auth/provider.d.ts.map +1 -0
- package/dist/src/auth/provider.js +41 -0
- package/dist/src/execution/index.d.ts +3 -2
- package/dist/src/execution/index.d.ts.map +1 -1
- package/dist/src/execution/index.js +11 -9
- package/dist/src/execution/utils.d.ts +7 -2
- package/dist/src/execution/utils.d.ts.map +1 -1
- package/dist/src/execution/utils.js +109 -20
- package/dist/src/index.d.ts +3 -3
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +6 -5
- package/dist/src/jwt-server/digest.d.ts +11 -0
- package/dist/src/jwt-server/digest.d.ts.map +1 -0
- package/dist/src/jwt-server/digest.js +22 -0
- package/dist/src/jwt-server/express.d.ts +16 -0
- package/dist/src/jwt-server/express.d.ts.map +1 -0
- package/dist/src/jwt-server/express.js +24 -0
- package/dist/src/jwt-server/handlers.d.ts +10 -0
- package/dist/src/jwt-server/handlers.d.ts.map +1 -0
- package/dist/src/jwt-server/handlers.js +41 -0
- package/dist/src/jwt-server/index.d.ts +8 -0
- package/dist/src/jwt-server/index.d.ts.map +1 -0
- package/dist/src/jwt-server/index.js +18 -0
- package/dist/src/jwt-server/jcs.d.ts +12 -0
- package/dist/src/jwt-server/jcs.d.ts.map +1 -0
- package/dist/src/jwt-server/jcs.js +60 -0
- package/dist/src/jwt-server/signer.d.ts +18 -0
- package/dist/src/jwt-server/signer.d.ts.map +1 -0
- package/dist/src/jwt-server/signer.js +71 -0
- package/dist/src/jwt-server/sponsorship.d.ts +19 -0
- package/dist/src/jwt-server/sponsorship.d.ts.map +1 -0
- package/dist/src/jwt-server/sponsorship.js +56 -0
- package/dist/src/jwt-server/web.d.ts +4 -0
- package/dist/src/jwt-server/web.d.ts.map +1 -0
- package/dist/src/jwt-server/web.js +27 -0
- package/dist/src/modules/validators/index.d.ts +2 -2
- package/dist/src/modules/validators/index.d.ts.map +1 -1
- package/dist/src/modules/validators/index.js +4 -1
- package/dist/src/modules/validators/policies/claim/permit2.d.ts +55 -0
- package/dist/src/modules/validators/policies/claim/permit2.d.ts.map +1 -0
- package/dist/src/modules/validators/policies/claim/permit2.js +239 -0
- package/dist/src/modules/validators/policies/claim/types.d.ts +12 -0
- package/dist/src/modules/validators/policies/claim/types.d.ts.map +1 -0
- package/dist/src/modules/validators/policies/claim/types.js +18 -0
- package/dist/src/modules/validators/smart-sessions.d.ts +15 -4
- package/dist/src/modules/validators/smart-sessions.d.ts.map +1 -1
- package/dist/src/modules/validators/smart-sessions.js +63 -19
- package/dist/src/orchestrator/client.d.ts +9 -4
- package/dist/src/orchestrator/client.d.ts.map +1 -1
- package/dist/src/orchestrator/client.js +29 -17
- package/dist/src/orchestrator/consts.d.ts +3 -2
- package/dist/src/orchestrator/consts.d.ts.map +1 -1
- package/dist/src/orchestrator/consts.js +4 -2
- package/dist/src/orchestrator/index.d.ts +4 -3
- package/dist/src/orchestrator/index.d.ts.map +1 -1
- package/dist/src/orchestrator/index.js +2 -2
- package/dist/src/orchestrator/registry.d.ts.map +1 -1
- package/dist/src/orchestrator/registry.js +5 -1
- package/dist/src/orchestrator/types.d.ts +6 -1
- package/dist/src/orchestrator/types.d.ts.map +1 -1
- package/dist/src/types.d.ts +64 -3
- package/dist/src/types.d.ts.map +1 -1
- package/package.json +18 -4
- package/dist/src/accounts/index.test.d.ts +0 -2
- package/dist/src/accounts/index.test.d.ts.map +0 -1
- package/dist/src/accounts/index.test.js +0 -33
- package/dist/src/accounts/json-rpc/index.test.d.ts +0 -2
- package/dist/src/accounts/json-rpc/index.test.d.ts.map +0 -1
- package/dist/src/accounts/json-rpc/index.test.js +0 -35
- package/dist/src/accounts/json-rpc/providers.test.d.ts +0 -2
- package/dist/src/accounts/json-rpc/providers.test.d.ts.map +0 -1
- package/dist/src/accounts/json-rpc/providers.test.js +0 -43
- package/dist/src/accounts/kernel.test.d.ts +0 -2
- package/dist/src/accounts/kernel.test.d.ts.map +0 -1
- package/dist/src/accounts/kernel.test.js +0 -132
- package/dist/src/accounts/nexus.test.d.ts +0 -2
- package/dist/src/accounts/nexus.test.d.ts.map +0 -1
- package/dist/src/accounts/nexus.test.js +0 -118
- package/dist/src/accounts/safe.test.d.ts +0 -2
- package/dist/src/accounts/safe.test.d.ts.map +0 -1
- package/dist/src/accounts/safe.test.js +0 -168
- package/dist/src/accounts/signing/passkeys.test.d.ts +0 -2
- package/dist/src/accounts/signing/passkeys.test.d.ts.map +0 -1
- package/dist/src/accounts/signing/passkeys.test.js +0 -88
- package/dist/src/accounts/startale.test.d.ts +0 -2
- package/dist/src/accounts/startale.test.d.ts.map +0 -1
- package/dist/src/accounts/startale.test.js +0 -189
- package/dist/src/accounts/utils.test.d.ts +0 -2
- package/dist/src/accounts/utils.test.d.ts.map +0 -1
- package/dist/src/accounts/utils.test.js +0 -49
- package/dist/src/actions/ecdsa.test.d.ts +0 -2
- package/dist/src/actions/ecdsa.test.d.ts.map +0 -1
- package/dist/src/actions/ecdsa.test.js +0 -99
- package/dist/src/actions/passkeys.test.d.ts +0 -2
- package/dist/src/actions/passkeys.test.d.ts.map +0 -1
- package/dist/src/actions/passkeys.test.js +0 -54
- package/dist/src/actions/recovery.test.d.ts +0 -2
- package/dist/src/actions/recovery.test.d.ts.map +0 -1
- package/dist/src/actions/recovery.test.js +0 -168
- package/dist/src/execution/utils.test.d.ts +0 -2
- package/dist/src/execution/utils.test.d.ts.map +0 -1
- package/dist/src/execution/utils.test.js +0 -205
- package/dist/src/modules/index.test.d.ts +0 -2
- package/dist/src/modules/index.test.d.ts.map +0 -1
- package/dist/src/modules/index.test.js +0 -81
- package/dist/src/modules/validators/core.test.d.ts +0 -2
- package/dist/src/modules/validators/core.test.d.ts.map +0 -1
- package/dist/src/modules/validators/core.test.js +0 -101
- package/dist/src/modules/validators/smart-sessions.test.d.ts +0 -2
- package/dist/src/modules/validators/smart-sessions.test.d.ts.map +0 -1
- package/dist/src/modules/validators/smart-sessions.test.js +0 -61
- package/dist/src/orchestrator/registry.test.d.ts +0 -2
- package/dist/src/orchestrator/registry.test.d.ts.map +0 -1
- package/dist/src/orchestrator/registry.test.js +0 -154
- package/dist/src/utils/index.test.d.ts +0 -2
- package/dist/src/utils/index.test.d.ts.map +0 -1
- package/dist/src/utils/index.test.js +0 -42
- package/dist/test/consts.d.ts +0 -10
- package/dist/test/consts.d.ts.map +0 -1
- package/dist/test/consts.js +0 -22
- package/dist/test/utils/utils.d.ts +0 -5
- package/dist/test/utils/utils.d.ts.map +0 -1
- package/dist/test/utils/utils.js +0 -20
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createJwtSigner = createJwtSigner;
|
|
4
|
+
const jose_1 = require("jose");
|
|
5
|
+
const digest_1 = require("./digest");
|
|
6
|
+
const sponsorship_1 = require("./sponsorship");
|
|
7
|
+
function pickAlg(jwk) {
|
|
8
|
+
if (jwk.kty === 'EC') {
|
|
9
|
+
if (jwk.crv === 'P-256')
|
|
10
|
+
return 'ES256';
|
|
11
|
+
if (jwk.crv === 'P-384')
|
|
12
|
+
return 'ES384';
|
|
13
|
+
if (jwk.crv === 'P-521')
|
|
14
|
+
return 'ES512';
|
|
15
|
+
throw new Error(`Unsupported EC curve: ${jwk.crv}`);
|
|
16
|
+
}
|
|
17
|
+
if (jwk.kty === 'RSA')
|
|
18
|
+
return 'RS256';
|
|
19
|
+
throw new Error(`Unsupported JWK kty: ${jwk.kty}`);
|
|
20
|
+
}
|
|
21
|
+
function createJwtSigner(config) {
|
|
22
|
+
const { jwt: { privateKey, integratorId, projectId, appId, keyId, audience = 'rhinestone-api', }, shouldSponsor: filters, } = config;
|
|
23
|
+
const alg = pickAlg(privateKey);
|
|
24
|
+
let cachedKey = null;
|
|
25
|
+
async function getKey() {
|
|
26
|
+
if (!cachedKey) {
|
|
27
|
+
cachedKey = (await (0, jose_1.importJWK)(privateKey, alg));
|
|
28
|
+
}
|
|
29
|
+
return cachedKey;
|
|
30
|
+
}
|
|
31
|
+
async function accessToken() {
|
|
32
|
+
const key = await getKey();
|
|
33
|
+
return new jose_1.SignJWT({ typ: 'access', app_id: appId })
|
|
34
|
+
.setProtectedHeader({ alg, kid: keyId })
|
|
35
|
+
.setIssuer(integratorId)
|
|
36
|
+
.setSubject(projectId)
|
|
37
|
+
.setAudience(audience)
|
|
38
|
+
.setIssuedAt()
|
|
39
|
+
.setExpirationTime('1h')
|
|
40
|
+
.sign(key);
|
|
41
|
+
}
|
|
42
|
+
async function getIntentExtensionToken(intentInput) {
|
|
43
|
+
if (filters) {
|
|
44
|
+
const allowed = await (0, sponsorship_1.shouldSponsor)(intentInput, filters);
|
|
45
|
+
if (!allowed) {
|
|
46
|
+
throw new sponsorship_1.SponsorshipDeniedError();
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
const key = await getKey();
|
|
50
|
+
const digest = await (0, digest_1.computeIntentInputDigest)(intentInput);
|
|
51
|
+
return new jose_1.SignJWT({
|
|
52
|
+
typ: 'intent_extension',
|
|
53
|
+
app_id: appId,
|
|
54
|
+
jti: crypto.randomUUID(),
|
|
55
|
+
policy: {
|
|
56
|
+
sponsorship: {
|
|
57
|
+
scope: 'intent',
|
|
58
|
+
intent_input: { digest },
|
|
59
|
+
},
|
|
60
|
+
},
|
|
61
|
+
})
|
|
62
|
+
.setProtectedHeader({ alg, kid: keyId })
|
|
63
|
+
.setIssuer(integratorId)
|
|
64
|
+
.setSubject(projectId)
|
|
65
|
+
.setAudience(audience)
|
|
66
|
+
.setIssuedAt()
|
|
67
|
+
.setExpirationTime('5m')
|
|
68
|
+
.sign(key);
|
|
69
|
+
}
|
|
70
|
+
return { accessToken, getIntentExtensionToken };
|
|
71
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { Address, Hex } from 'viem';
|
|
2
|
+
export declare class SponsorshipDeniedError extends Error {
|
|
3
|
+
constructor();
|
|
4
|
+
}
|
|
5
|
+
type MaybeAsync<T> = T | Promise<T>;
|
|
6
|
+
export interface SponsorshipFilter {
|
|
7
|
+
chain?: (chain: {
|
|
8
|
+
id: number;
|
|
9
|
+
}) => MaybeAsync<boolean>;
|
|
10
|
+
account?: (address: Address) => MaybeAsync<boolean>;
|
|
11
|
+
calls?: (calls: {
|
|
12
|
+
to: Address;
|
|
13
|
+
value: bigint;
|
|
14
|
+
data: Hex;
|
|
15
|
+
}[]) => MaybeAsync<boolean>;
|
|
16
|
+
}
|
|
17
|
+
export declare function shouldSponsor(intentInput: unknown, filters: SponsorshipFilter): Promise<boolean>;
|
|
18
|
+
export {};
|
|
19
|
+
//# sourceMappingURL=sponsorship.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sponsorship.d.ts","sourceRoot":"","sources":["../../../jwt-server/sponsorship.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,MAAM,CAAA;AAExC,qBAAa,sBAAuB,SAAQ,KAAK;;CAKhD;AAED,KAAK,UAAU,CAAC,CAAC,IAAI,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAAA;AAEnC,MAAM,WAAW,iBAAiB;IAChC,KAAK,CAAC,EAAE,CAAC,KAAK,EAAE;QAAE,EAAE,EAAE,MAAM,CAAA;KAAE,KAAK,UAAU,CAAC,OAAO,CAAC,CAAA;IACtD,OAAO,CAAC,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK,UAAU,CAAC,OAAO,CAAC,CAAA;IACnD,KAAK,CAAC,EAAE,CACN,KAAK,EAAE;QAAE,EAAE,EAAE,OAAO,CAAC;QAAC,KAAK,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,GAAG,CAAA;KAAE,EAAE,KAC/C,UAAU,CAAC,OAAO,CAAC,CAAA;CACzB;AAiDD,wBAAsB,aAAa,CACjC,WAAW,EAAE,OAAO,EACpB,OAAO,EAAE,iBAAiB,GACzB,OAAO,CAAC,OAAO,CAAC,CAclB"}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SponsorshipDeniedError = void 0;
|
|
4
|
+
exports.shouldSponsor = shouldSponsor;
|
|
5
|
+
class SponsorshipDeniedError extends Error {
|
|
6
|
+
constructor() {
|
|
7
|
+
super('Sponsorship denied');
|
|
8
|
+
this.name = 'SponsorshipDeniedError';
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
exports.SponsorshipDeniedError = SponsorshipDeniedError;
|
|
12
|
+
function parseIntentInput(intentInput) {
|
|
13
|
+
if (typeof intentInput !== 'object' || intentInput === null) {
|
|
14
|
+
throw new Error('intentInput must be a non-null object');
|
|
15
|
+
}
|
|
16
|
+
const input = intentInput;
|
|
17
|
+
const chainId = input.destinationChainId;
|
|
18
|
+
if (typeof chainId !== 'number') {
|
|
19
|
+
throw new Error('intentInput.destinationChainId must be a number');
|
|
20
|
+
}
|
|
21
|
+
const account = input.account;
|
|
22
|
+
if (typeof account !== 'object' || account === null) {
|
|
23
|
+
throw new Error('intentInput.account must be a non-null object');
|
|
24
|
+
}
|
|
25
|
+
const address = account.address;
|
|
26
|
+
if (typeof address !== 'string') {
|
|
27
|
+
throw new Error('intentInput.account.address must be a string');
|
|
28
|
+
}
|
|
29
|
+
const executions = input.destinationExecutions;
|
|
30
|
+
if (!Array.isArray(executions)) {
|
|
31
|
+
throw new Error('intentInput.destinationExecutions must be an array');
|
|
32
|
+
}
|
|
33
|
+
const calls = executions.map((exec) => ({
|
|
34
|
+
to: exec.to,
|
|
35
|
+
value: BigInt(exec.value),
|
|
36
|
+
data: exec.data,
|
|
37
|
+
}));
|
|
38
|
+
return {
|
|
39
|
+
chain: { id: chainId },
|
|
40
|
+
account: address,
|
|
41
|
+
calls,
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
async function shouldSponsor(intentInput, filters) {
|
|
45
|
+
const parsed = parseIntentInput(intentInput);
|
|
46
|
+
if (filters.chain && !(await filters.chain(parsed.chain))) {
|
|
47
|
+
return false;
|
|
48
|
+
}
|
|
49
|
+
if (filters.account && !(await filters.account(parsed.account))) {
|
|
50
|
+
return false;
|
|
51
|
+
}
|
|
52
|
+
if (filters.calls && !(await filters.calls(parsed.calls))) {
|
|
53
|
+
return false;
|
|
54
|
+
}
|
|
55
|
+
return true;
|
|
56
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { type JwtHandlerConfig } from './handlers';
|
|
2
|
+
export declare function createAccessTokenHandler(config: JwtHandlerConfig): (req: Request) => Promise<Response>;
|
|
3
|
+
export declare function createExtensionTokenHandler(config: JwtHandlerConfig): (req: Request) => Promise<Response>;
|
|
4
|
+
//# sourceMappingURL=web.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"web.d.ts","sourceRoot":"","sources":["../../../jwt-server/web.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,KAAK,gBAAgB,EACtB,MAAM,YAAY,CAAA;AAEnB,wBAAgB,wBAAwB,CACtC,MAAM,EAAE,gBAAgB,GACvB,CAAC,GAAG,EAAE,OAAO,KAAK,OAAO,CAAC,QAAQ,CAAC,CAOrC;AAED,wBAAgB,2BAA2B,CACzC,MAAM,EAAE,gBAAgB,GACvB,CAAC,GAAG,EAAE,OAAO,KAAK,OAAO,CAAC,QAAQ,CAAC,CAerC"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createAccessTokenHandler = createAccessTokenHandler;
|
|
4
|
+
exports.createExtensionTokenHandler = createExtensionTokenHandler;
|
|
5
|
+
const handlers_1 = require("./handlers");
|
|
6
|
+
function createAccessTokenHandler(config) {
|
|
7
|
+
const handle = (0, handlers_1.createCoreAccessTokenHandler)(config);
|
|
8
|
+
return async () => {
|
|
9
|
+
const result = await handle();
|
|
10
|
+
return Response.json(result.body, { status: result.status });
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
function createExtensionTokenHandler(config) {
|
|
14
|
+
const handle = (0, handlers_1.createCoreExtensionTokenHandler)(config);
|
|
15
|
+
return async (req) => {
|
|
16
|
+
let intentInput;
|
|
17
|
+
try {
|
|
18
|
+
const body = await req.json();
|
|
19
|
+
intentInput = body.intentInput;
|
|
20
|
+
}
|
|
21
|
+
catch {
|
|
22
|
+
return Response.json({ error: 'Invalid JSON body' }, { status: 400 });
|
|
23
|
+
}
|
|
24
|
+
const result = await handle(intentInput);
|
|
25
|
+
return Response.json(result.body, { status: result.status });
|
|
26
|
+
};
|
|
27
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { getMockSignature, getOwnerValidator, MULTI_FACTOR_VALIDATOR_ADDRESS, OWNABLE_VALIDATOR_ADDRESS, SMART_SESSION_EMISSARY_ADDRESS, WEBAUTHN_VALIDATOR_ADDRESS } from './core';
|
|
2
|
-
import { buildMockSignature, getEnableSessionCall, getPermissionId, getSmartSessionValidator, isSessionEnabled } from './smart-sessions';
|
|
3
|
-
export { OWNABLE_VALIDATOR_ADDRESS, WEBAUTHN_VALIDATOR_ADDRESS, MULTI_FACTOR_VALIDATOR_ADDRESS, SMART_SESSION_EMISSARY_ADDRESS, getOwnerValidator, getSmartSessionValidator, getEnableSessionCall, getPermissionId, getMockSignature, buildMockSignature, isSessionEnabled, };
|
|
2
|
+
import { buildMockSignature, DUMMY_PRECLAIMOP_SELECTOR, DUMMY_PRECLAIMOP_TARGET, getEnableSessionCall, getPermissionId, getSmartSessionValidator, isSessionEnabled, packSignature } from './smart-sessions';
|
|
3
|
+
export { OWNABLE_VALIDATOR_ADDRESS, WEBAUTHN_VALIDATOR_ADDRESS, MULTI_FACTOR_VALIDATOR_ADDRESS, SMART_SESSION_EMISSARY_ADDRESS, DUMMY_PRECLAIMOP_TARGET, DUMMY_PRECLAIMOP_SELECTOR, getOwnerValidator, getSmartSessionValidator, getEnableSessionCall, getPermissionId, getMockSignature, buildMockSignature, isSessionEnabled, packSignature, };
|
|
4
4
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../modules/validators/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,gBAAgB,EAChB,iBAAiB,EACjB,8BAA8B,EAC9B,yBAAyB,EACzB,8BAA8B,EAC9B,0BAA0B,EAC3B,MAAM,QAAQ,CAAA;AACf,OAAO,EACL,kBAAkB,EAClB,oBAAoB,EACpB,eAAe,EACf,wBAAwB,EACxB,gBAAgB,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../modules/validators/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,gBAAgB,EAChB,iBAAiB,EACjB,8BAA8B,EAC9B,yBAAyB,EACzB,8BAA8B,EAC9B,0BAA0B,EAC3B,MAAM,QAAQ,CAAA;AACf,OAAO,EACL,kBAAkB,EAClB,yBAAyB,EACzB,uBAAuB,EACvB,oBAAoB,EACpB,eAAe,EACf,wBAAwB,EACxB,gBAAgB,EAChB,aAAa,EACd,MAAM,kBAAkB,CAAA;AAEzB,OAAO,EACL,yBAAyB,EACzB,0BAA0B,EAC1B,8BAA8B,EAC9B,8BAA8B,EAC9B,uBAAuB,EACvB,yBAAyB,EACzB,iBAAiB,EACjB,wBAAwB,EACxB,oBAAoB,EACpB,eAAe,EACf,gBAAgB,EAChB,kBAAkB,EAClB,gBAAgB,EAChB,aAAa,GACd,CAAA"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isSessionEnabled = exports.buildMockSignature = exports.getMockSignature = exports.getPermissionId = exports.getEnableSessionCall = exports.getSmartSessionValidator = exports.getOwnerValidator = exports.SMART_SESSION_EMISSARY_ADDRESS = exports.MULTI_FACTOR_VALIDATOR_ADDRESS = exports.WEBAUTHN_VALIDATOR_ADDRESS = exports.OWNABLE_VALIDATOR_ADDRESS = void 0;
|
|
3
|
+
exports.packSignature = exports.isSessionEnabled = exports.buildMockSignature = exports.getMockSignature = exports.getPermissionId = exports.getEnableSessionCall = exports.getSmartSessionValidator = exports.getOwnerValidator = exports.DUMMY_PRECLAIMOP_SELECTOR = exports.DUMMY_PRECLAIMOP_TARGET = exports.SMART_SESSION_EMISSARY_ADDRESS = exports.MULTI_FACTOR_VALIDATOR_ADDRESS = exports.WEBAUTHN_VALIDATOR_ADDRESS = exports.OWNABLE_VALIDATOR_ADDRESS = void 0;
|
|
4
4
|
const core_1 = require("./core");
|
|
5
5
|
Object.defineProperty(exports, "getMockSignature", { enumerable: true, get: function () { return core_1.getMockSignature; } });
|
|
6
6
|
Object.defineProperty(exports, "getOwnerValidator", { enumerable: true, get: function () { return core_1.getOwnerValidator; } });
|
|
@@ -10,7 +10,10 @@ Object.defineProperty(exports, "SMART_SESSION_EMISSARY_ADDRESS", { enumerable: t
|
|
|
10
10
|
Object.defineProperty(exports, "WEBAUTHN_VALIDATOR_ADDRESS", { enumerable: true, get: function () { return core_1.WEBAUTHN_VALIDATOR_ADDRESS; } });
|
|
11
11
|
const smart_sessions_1 = require("./smart-sessions");
|
|
12
12
|
Object.defineProperty(exports, "buildMockSignature", { enumerable: true, get: function () { return smart_sessions_1.buildMockSignature; } });
|
|
13
|
+
Object.defineProperty(exports, "DUMMY_PRECLAIMOP_SELECTOR", { enumerable: true, get: function () { return smart_sessions_1.DUMMY_PRECLAIMOP_SELECTOR; } });
|
|
14
|
+
Object.defineProperty(exports, "DUMMY_PRECLAIMOP_TARGET", { enumerable: true, get: function () { return smart_sessions_1.DUMMY_PRECLAIMOP_TARGET; } });
|
|
13
15
|
Object.defineProperty(exports, "getEnableSessionCall", { enumerable: true, get: function () { return smart_sessions_1.getEnableSessionCall; } });
|
|
14
16
|
Object.defineProperty(exports, "getPermissionId", { enumerable: true, get: function () { return smart_sessions_1.getPermissionId; } });
|
|
15
17
|
Object.defineProperty(exports, "getSmartSessionValidator", { enumerable: true, get: function () { return smart_sessions_1.getSmartSessionValidator; } });
|
|
16
18
|
Object.defineProperty(exports, "isSessionEnabled", { enumerable: true, get: function () { return smart_sessions_1.isSessionEnabled; } });
|
|
19
|
+
Object.defineProperty(exports, "packSignature", { enumerable: true, get: function () { return smart_sessions_1.packSignature; } });
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { type Address, type Hex } from 'viem';
|
|
2
|
+
import type { Permit2ClaimPolicy } from '../../../../types';
|
|
3
|
+
/** Typed representation of the Permit2 message fields used for calldata building */
|
|
4
|
+
export interface Permit2ClaimMessage {
|
|
5
|
+
permitted: readonly {
|
|
6
|
+
token: Address;
|
|
7
|
+
amount: bigint;
|
|
8
|
+
}[];
|
|
9
|
+
spender: Address;
|
|
10
|
+
nonce: bigint;
|
|
11
|
+
deadline: bigint;
|
|
12
|
+
mandate: {
|
|
13
|
+
target: {
|
|
14
|
+
recipient: Address;
|
|
15
|
+
tokenOut: readonly {
|
|
16
|
+
token: Address;
|
|
17
|
+
amount: bigint;
|
|
18
|
+
}[];
|
|
19
|
+
targetChain: bigint;
|
|
20
|
+
fillExpiry: bigint;
|
|
21
|
+
};
|
|
22
|
+
minGas: bigint;
|
|
23
|
+
originOps: {
|
|
24
|
+
vt: Hex;
|
|
25
|
+
ops: readonly {
|
|
26
|
+
to: Address;
|
|
27
|
+
value: bigint;
|
|
28
|
+
data: Hex;
|
|
29
|
+
}[];
|
|
30
|
+
};
|
|
31
|
+
destOps: {
|
|
32
|
+
vt: Hex;
|
|
33
|
+
ops: readonly {
|
|
34
|
+
to: Address;
|
|
35
|
+
value: bigint;
|
|
36
|
+
data: Hex;
|
|
37
|
+
}[];
|
|
38
|
+
};
|
|
39
|
+
q: Hex;
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Builds the policySpecificData calldata for a Permit2ClaimPolicy EIP-1271 check.
|
|
44
|
+
*
|
|
45
|
+
* Format (derived from Permit2ClaimPolicy.sol calldata layout):
|
|
46
|
+
* Header: [spender:20][nonce:32][deadline:32]
|
|
47
|
+
* TokenIn: expanded [count:1][token:32][amount:32]... OR pre-computed hash [32]
|
|
48
|
+
* Mandate: if any target check enabled — expanded target + minGas:16 + ops hashes + q
|
|
49
|
+
* else — pre-computed mandateHash [32]
|
|
50
|
+
*
|
|
51
|
+
*/
|
|
52
|
+
export declare function buildPermit2ClaimPolicyCalldata(policy: Permit2ClaimPolicy, message: Permit2ClaimMessage): Hex;
|
|
53
|
+
export declare const PERMIT2_CLAIM_POLICY_ADDRESS: Address;
|
|
54
|
+
export declare function encodePermit2ClaimPolicyInitData(policy: Permit2ClaimPolicy): Hex;
|
|
55
|
+
//# sourceMappingURL=permit2.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"permit2.d.ts","sourceRoot":"","sources":["../../../../../../modules/validators/policies/claim/permit2.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,OAAO,EAIZ,KAAK,GAAG,EAKT,MAAM,MAAM,CAAA;AACb,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAA;AAiD3D,oFAAoF;AACpF,MAAM,WAAW,mBAAmB;IAClC,SAAS,EAAE,SAAS;QAAE,KAAK,EAAE,OAAO,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAE,EAAE,CAAA;IACxD,OAAO,EAAE,OAAO,CAAA;IAChB,KAAK,EAAE,MAAM,CAAA;IACb,QAAQ,EAAE,MAAM,CAAA;IAChB,OAAO,EAAE;QACP,MAAM,EAAE;YACN,SAAS,EAAE,OAAO,CAAA;YAClB,QAAQ,EAAE,SAAS;gBAAE,KAAK,EAAE,OAAO,CAAC;gBAAC,MAAM,EAAE,MAAM,CAAA;aAAE,EAAE,CAAA;YACvD,WAAW,EAAE,MAAM,CAAA;YACnB,UAAU,EAAE,MAAM,CAAA;SACnB,CAAA;QACD,MAAM,EAAE,MAAM,CAAA;QACd,SAAS,EAAE;YACT,EAAE,EAAE,GAAG,CAAA;YACP,GAAG,EAAE,SAAS;gBAAE,EAAE,EAAE,OAAO,CAAC;gBAAC,KAAK,EAAE,MAAM,CAAC;gBAAC,IAAI,EAAE,GAAG,CAAA;aAAE,EAAE,CAAA;SAC1D,CAAA;QACD,OAAO,EAAE;YACP,EAAE,EAAE,GAAG,CAAA;YACP,GAAG,EAAE,SAAS;gBAAE,EAAE,EAAE,OAAO,CAAC;gBAAC,KAAK,EAAE,MAAM,CAAC;gBAAC,IAAI,EAAE,GAAG,CAAA;aAAE,EAAE,CAAA;SAC1D,CAAA;QACD,CAAC,EAAE,GAAG,CAAA;KACP,CAAA;CACF;AA+ED;;;;;;;;;GASG;AACH,wBAAgB,+BAA+B,CAC7C,MAAM,EAAE,kBAAkB,EAC1B,OAAO,EAAE,mBAAmB,GAC3B,GAAG,CA2EL;AAED,eAAO,MAAM,4BAA4B,EAAE,OACG,CAAA;AAE9C,wBAAgB,gCAAgC,CAC9C,MAAM,EAAE,kBAAkB,GACzB,GAAG,CA2FL"}
|
|
@@ -0,0 +1,239 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PERMIT2_CLAIM_POLICY_ADDRESS = void 0;
|
|
4
|
+
exports.buildPermit2ClaimPolicyCalldata = buildPermit2ClaimPolicyCalldata;
|
|
5
|
+
exports.encodePermit2ClaimPolicyInitData = encodePermit2ClaimPolicyInitData;
|
|
6
|
+
const viem_1 = require("viem");
|
|
7
|
+
const types_1 = require("./types");
|
|
8
|
+
// EIP-712 type definitions for Permit2/Mandate struct encoding.
|
|
9
|
+
// Note: the token-out struct is named 'Token' in the Solidity contract (matching the
|
|
10
|
+
// signed Permit2 message types in execution/permit2.ts).
|
|
11
|
+
const PERMIT2_TYPES = {
|
|
12
|
+
TokenPermissions: [
|
|
13
|
+
{ name: 'token', type: 'address' },
|
|
14
|
+
{ name: 'amount', type: 'uint256' },
|
|
15
|
+
],
|
|
16
|
+
Token: [
|
|
17
|
+
{ name: 'token', type: 'address' },
|
|
18
|
+
{ name: 'amount', type: 'uint256' },
|
|
19
|
+
],
|
|
20
|
+
Ops: [
|
|
21
|
+
{ name: 'to', type: 'address' },
|
|
22
|
+
{ name: 'value', type: 'uint256' },
|
|
23
|
+
{ name: 'data', type: 'bytes' },
|
|
24
|
+
],
|
|
25
|
+
Op: [
|
|
26
|
+
{ name: 'vt', type: 'bytes32' },
|
|
27
|
+
{ name: 'ops', type: 'Ops[]' },
|
|
28
|
+
],
|
|
29
|
+
Target: [
|
|
30
|
+
{ name: 'recipient', type: 'address' },
|
|
31
|
+
{ name: 'tokenOut', type: 'Token[]' },
|
|
32
|
+
{ name: 'targetChain', type: 'uint256' },
|
|
33
|
+
{ name: 'fillExpiry', type: 'uint256' },
|
|
34
|
+
],
|
|
35
|
+
Mandate: [
|
|
36
|
+
{ name: 'target', type: 'Target' },
|
|
37
|
+
{ name: 'minGas', type: 'uint128' },
|
|
38
|
+
{ name: 'originOps', type: 'Op' },
|
|
39
|
+
{ name: 'destOps', type: 'Op' },
|
|
40
|
+
{ name: 'q', type: 'bytes32' },
|
|
41
|
+
],
|
|
42
|
+
};
|
|
43
|
+
// --- EIP-712 hash helpers ---
|
|
44
|
+
function hashArray(hashes) {
|
|
45
|
+
return (0, viem_1.keccak256)(hashes.length > 0 ? (0, viem_1.concat)(hashes) : '0x');
|
|
46
|
+
}
|
|
47
|
+
function hashTokenPermissionsArray(permitted) {
|
|
48
|
+
return hashArray(permitted.map(({ token, amount }) => (0, viem_1.hashStruct)({
|
|
49
|
+
primaryType: 'TokenPermissions',
|
|
50
|
+
types: PERMIT2_TYPES,
|
|
51
|
+
data: { token, amount },
|
|
52
|
+
})));
|
|
53
|
+
}
|
|
54
|
+
function hashTokenOutArray(tokenOut) {
|
|
55
|
+
return hashArray(tokenOut.map(({ token, amount }) => (0, viem_1.hashStruct)({
|
|
56
|
+
primaryType: 'Token',
|
|
57
|
+
types: PERMIT2_TYPES,
|
|
58
|
+
data: { token, amount },
|
|
59
|
+
})));
|
|
60
|
+
}
|
|
61
|
+
function hashOpStruct(op) {
|
|
62
|
+
return (0, viem_1.hashStruct)({
|
|
63
|
+
primaryType: 'Op',
|
|
64
|
+
types: PERMIT2_TYPES,
|
|
65
|
+
data: { vt: op.vt, ops: Array.from(op.ops) },
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
function hashMandateStruct(mandate) {
|
|
69
|
+
return (0, viem_1.hashStruct)({
|
|
70
|
+
primaryType: 'Mandate',
|
|
71
|
+
types: PERMIT2_TYPES,
|
|
72
|
+
data: {
|
|
73
|
+
target: {
|
|
74
|
+
recipient: mandate.target.recipient,
|
|
75
|
+
tokenOut: Array.from(mandate.target.tokenOut),
|
|
76
|
+
targetChain: mandate.target.targetChain,
|
|
77
|
+
fillExpiry: mandate.target.fillExpiry,
|
|
78
|
+
},
|
|
79
|
+
minGas: mandate.minGas,
|
|
80
|
+
originOps: {
|
|
81
|
+
vt: mandate.originOps.vt,
|
|
82
|
+
ops: Array.from(mandate.originOps.ops),
|
|
83
|
+
},
|
|
84
|
+
destOps: { vt: mandate.destOps.vt, ops: Array.from(mandate.destOps.ops) },
|
|
85
|
+
q: mandate.q,
|
|
86
|
+
},
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
// --- Token array encoding helpers ---
|
|
90
|
+
/** Encodes a token+amount pair as [token_as_uint256:32][amount:32] (64 bytes) */
|
|
91
|
+
function encodeTokenEntry(token, amount) {
|
|
92
|
+
return (0, viem_1.encodeAbiParameters)([{ type: 'address' }, { type: 'uint256' }], [token, amount]);
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Builds the policySpecificData calldata for a Permit2ClaimPolicy EIP-1271 check.
|
|
96
|
+
*
|
|
97
|
+
* Format (derived from Permit2ClaimPolicy.sol calldata layout):
|
|
98
|
+
* Header: [spender:20][nonce:32][deadline:32]
|
|
99
|
+
* TokenIn: expanded [count:1][token:32][amount:32]... OR pre-computed hash [32]
|
|
100
|
+
* Mandate: if any target check enabled — expanded target + minGas:16 + ops hashes + q
|
|
101
|
+
* else — pre-computed mandateHash [32]
|
|
102
|
+
*
|
|
103
|
+
*/
|
|
104
|
+
function buildPermit2ClaimPolicyCalldata(policy, message) {
|
|
105
|
+
const tokenInEnabled = !!policy.tokensIn?.length;
|
|
106
|
+
const recipientEnabled = !!policy.recipients?.length;
|
|
107
|
+
const fillExpiryEnabled = !!policy.fillExpiryBounds?.length;
|
|
108
|
+
const tokenOutEnabled = !!policy.tokensOut?.length;
|
|
109
|
+
const recipientIsSponsorEnabled = !!policy.recipientIsSponsor;
|
|
110
|
+
// hasAnyTargetCheck mirrors the Solidity MASK_TARGET_CHECKS logic for our supported fields
|
|
111
|
+
const hasAnyTargetCheck = recipientEnabled ||
|
|
112
|
+
fillExpiryEnabled ||
|
|
113
|
+
tokenOutEnabled ||
|
|
114
|
+
recipientIsSponsorEnabled;
|
|
115
|
+
const parts = [];
|
|
116
|
+
// Header: [spender:20][nonce:32][deadline:32] (spender == arbiter in Permit2 context)
|
|
117
|
+
parts.push((0, viem_1.encodePacked)(['address', 'uint256', 'uint256'], [message.spender, message.nonce, message.deadline]));
|
|
118
|
+
// TokenIn section
|
|
119
|
+
if (tokenInEnabled) {
|
|
120
|
+
// Expanded: [count:1][token_as_uint256:32][amount:32]...
|
|
121
|
+
if (message.permitted.length > 255)
|
|
122
|
+
throw new Error('permitted array exceeds max length of 255');
|
|
123
|
+
parts.push((0, viem_1.toHex)(message.permitted.length, { size: 1 }));
|
|
124
|
+
for (const { token, amount } of message.permitted) {
|
|
125
|
+
parts.push(encodeTokenEntry(token, amount));
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
else {
|
|
129
|
+
parts.push(hashTokenPermissionsArray(message.permitted));
|
|
130
|
+
}
|
|
131
|
+
// Mandate section
|
|
132
|
+
if (!hasAnyTargetCheck) {
|
|
133
|
+
// No mandate-level checks enabled — provide pre-computed mandateHash
|
|
134
|
+
parts.push(hashMandateStruct(message.mandate));
|
|
135
|
+
}
|
|
136
|
+
else {
|
|
137
|
+
// Expanded mandate: target fields + minGas + ops hashes + q
|
|
138
|
+
const target = message.mandate.target;
|
|
139
|
+
// Target: [recipient:20][targetChain:32][fillExpiry:32]
|
|
140
|
+
parts.push((0, viem_1.encodePacked)(['address', 'uint256', 'uint256'], [target.recipient, target.targetChain, target.fillExpiry]));
|
|
141
|
+
// TokenOut (inside target)
|
|
142
|
+
if (tokenOutEnabled) {
|
|
143
|
+
if (target.tokenOut.length > 255)
|
|
144
|
+
throw new Error('tokenOut array exceeds max length of 255');
|
|
145
|
+
parts.push((0, viem_1.toHex)(target.tokenOut.length, { size: 1 }));
|
|
146
|
+
for (const { token, amount } of target.tokenOut) {
|
|
147
|
+
parts.push(encodeTokenEntry(token, amount));
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
else {
|
|
151
|
+
parts.push(hashTokenOutArray(target.tokenOut));
|
|
152
|
+
}
|
|
153
|
+
// minGas: uint128 = 16 bytes
|
|
154
|
+
parts.push((0, viem_1.toHex)(message.mandate.minGas, { size: 16 }));
|
|
155
|
+
// originOpsHash and destOpsHash: always 32-byte hashes (we don't support ops checks)
|
|
156
|
+
parts.push(hashOpStruct(message.mandate.originOps));
|
|
157
|
+
parts.push(hashOpStruct(message.mandate.destOps));
|
|
158
|
+
// qualificationHash: q is already keccak256(qualifier.encodedVal)
|
|
159
|
+
parts.push(message.mandate.q);
|
|
160
|
+
}
|
|
161
|
+
return (0, viem_1.concat)(parts);
|
|
162
|
+
}
|
|
163
|
+
exports.PERMIT2_CLAIM_POLICY_ADDRESS = '0x62E3588C6d861C9f986E82EC3757434EDF16ce91';
|
|
164
|
+
function encodePermit2ClaimPolicyInitData(policy) {
|
|
165
|
+
let modeConfig = 0;
|
|
166
|
+
const setMode = (fieldId) => {
|
|
167
|
+
modeConfig |= types_1.MODE_CHECK_STORAGE << (fieldId * 2);
|
|
168
|
+
};
|
|
169
|
+
if (policy.arbiters?.length)
|
|
170
|
+
setMode(types_1.FIELD_ARBITER);
|
|
171
|
+
if (policy.expiryBounds)
|
|
172
|
+
setMode(types_1.FIELD_EXPIRY);
|
|
173
|
+
if (policy.tokensIn?.length)
|
|
174
|
+
setMode(types_1.FIELD_TOKEN_IN);
|
|
175
|
+
if (policy.recipients?.length)
|
|
176
|
+
setMode(types_1.FIELD_RECIPIENT);
|
|
177
|
+
if (policy.fillExpiryBounds?.length)
|
|
178
|
+
setMode(types_1.FIELD_FILL_EXPIRY);
|
|
179
|
+
if (policy.tokensOut?.length)
|
|
180
|
+
setMode(types_1.FIELD_TOKEN_OUT);
|
|
181
|
+
if (policy.recipientIsSponsor)
|
|
182
|
+
setMode(types_1.FIELD_RECIPIENT_IS_SPONSOR);
|
|
183
|
+
const parts = [(0, viem_1.toHex)(modeConfig, { size: 4 })];
|
|
184
|
+
// Arbiter: [count: 1][address: 20] each
|
|
185
|
+
if (policy.arbiters?.length) {
|
|
186
|
+
if (policy.arbiters.length > 255)
|
|
187
|
+
throw new Error('arbiters array exceeds max length of 255');
|
|
188
|
+
parts.push((0, viem_1.encodePacked)(['uint8', ...policy.arbiters.map(() => 'address')], [policy.arbiters.length, ...policy.arbiters]));
|
|
189
|
+
}
|
|
190
|
+
// Expiry: [maxExpiry: 16][minExpiry: 16] packed into uint256
|
|
191
|
+
if (policy.expiryBounds) {
|
|
192
|
+
const mask128 = (1n << 128n) - 1n;
|
|
193
|
+
const min = (policy.expiryBounds.min ?? 0n) & mask128;
|
|
194
|
+
const max = (policy.expiryBounds.max ?? viem_1.maxUint256) & mask128;
|
|
195
|
+
parts.push((0, viem_1.toHex)((min & mask128) | (max << 128n), { size: 32 }));
|
|
196
|
+
}
|
|
197
|
+
// TokenIn: [count: 1][chainId: 32][token: 20] each
|
|
198
|
+
if (policy.tokensIn?.length) {
|
|
199
|
+
if (policy.tokensIn.length > 255)
|
|
200
|
+
throw new Error('tokensIn array exceeds max length of 255');
|
|
201
|
+
parts.push((0, viem_1.toHex)(policy.tokensIn.length, { size: 1 }));
|
|
202
|
+
for (const { chainId, token } of policy.tokensIn) {
|
|
203
|
+
parts.push((0, viem_1.encodePacked)(['uint256', 'address'], [BigInt(chainId), token]));
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
// Recipient: [count: 1][chainId: 32][recipient: 20] each
|
|
207
|
+
if (policy.recipients?.length) {
|
|
208
|
+
if (policy.recipients.length > 255)
|
|
209
|
+
throw new Error('recipients array exceeds max length of 255');
|
|
210
|
+
parts.push((0, viem_1.toHex)(policy.recipients.length, { size: 1 }));
|
|
211
|
+
for (const { chainId, recipient } of policy.recipients) {
|
|
212
|
+
parts.push((0, viem_1.encodePacked)(['uint256', 'address'], [BigInt(chainId), recipient === 'any' ? types_1.ANY_ADDRESS : recipient]));
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
// FillExpiry: [count: 1][chainId: 32][max<<128|min packed into uint256] each
|
|
216
|
+
if (policy.fillExpiryBounds?.length) {
|
|
217
|
+
if (policy.fillExpiryBounds.length > 255)
|
|
218
|
+
throw new Error('fillExpiryBounds array exceeds max length of 255');
|
|
219
|
+
const mask128 = (1n << 128n) - 1n;
|
|
220
|
+
parts.push((0, viem_1.toHex)(policy.fillExpiryBounds.length, { size: 1 }));
|
|
221
|
+
for (const { chainId, min: fMin, max: fMax } of policy.fillExpiryBounds) {
|
|
222
|
+
const minVal = (fMin ?? 0n) & mask128;
|
|
223
|
+
const maxVal = (fMax ?? viem_1.maxUint256) & mask128;
|
|
224
|
+
const packed = minVal | (maxVal << 128n);
|
|
225
|
+
parts.push((0, viem_1.encodePacked)(['uint256', 'uint256'], [BigInt(chainId), packed]));
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
// TokenOut: [count: 1][chainId: 32][token: 20] each
|
|
229
|
+
if (policy.tokensOut?.length) {
|
|
230
|
+
if (policy.tokensOut.length > 255)
|
|
231
|
+
throw new Error('tokensOut array exceeds max length of 255');
|
|
232
|
+
parts.push((0, viem_1.toHex)(policy.tokensOut.length, { size: 1 }));
|
|
233
|
+
for (const { chainId, token } of policy.tokensOut) {
|
|
234
|
+
parts.push((0, viem_1.encodePacked)(['uint256', 'address'], [BigInt(chainId), token]));
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
// RecipientIsSponsor has no data payload — mode bit alone enables it
|
|
238
|
+
return (0, viem_1.concat)(parts);
|
|
239
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export declare const FIELD_ARBITER = 0;
|
|
2
|
+
export declare const FIELD_EXPIRY = 1;
|
|
3
|
+
export declare const FIELD_TOKEN_IN = 2;
|
|
4
|
+
export declare const FIELD_RECIPIENT = 3;
|
|
5
|
+
export declare const FIELD_FILL_EXPIRY = 4;
|
|
6
|
+
export declare const FIELD_TOKEN_OUT = 5;
|
|
7
|
+
export declare const FIELD_ORIGIN_OPS = 6;
|
|
8
|
+
export declare const FIELD_DEST_OPS = 7;
|
|
9
|
+
export declare const FIELD_RECIPIENT_IS_SPONSOR = 9;
|
|
10
|
+
export declare const MODE_CHECK_STORAGE = 1;
|
|
11
|
+
export declare const ANY_ADDRESS: "0xFFfFfFffFFfffFFfFFfFFFFFffFFFffffFfFFFfF";
|
|
12
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../../../modules/validators/policies/claim/types.ts"],"names":[],"mappings":"AACA,eAAO,MAAM,aAAa,IAAI,CAAA;AAC9B,eAAO,MAAM,YAAY,IAAI,CAAA;AAC7B,eAAO,MAAM,cAAc,IAAI,CAAA;AAC/B,eAAO,MAAM,eAAe,IAAI,CAAA;AAChC,eAAO,MAAM,iBAAiB,IAAI,CAAA;AAClC,eAAO,MAAM,eAAe,IAAI,CAAA;AAChC,eAAO,MAAM,gBAAgB,IAAI,CAAA;AACjC,eAAO,MAAM,cAAc,IAAI,CAAA;AAE/B,eAAO,MAAM,0BAA0B,IAAI,CAAA;AAG3C,eAAO,MAAM,kBAAkB,IAAI,CAAA;AAGnC,eAAO,MAAM,WAAW,EAAG,4CAAqD,CAAA"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ANY_ADDRESS = exports.MODE_CHECK_STORAGE = exports.FIELD_RECIPIENT_IS_SPONSOR = exports.FIELD_DEST_OPS = exports.FIELD_ORIGIN_OPS = exports.FIELD_TOKEN_OUT = exports.FIELD_FILL_EXPIRY = exports.FIELD_RECIPIENT = exports.FIELD_TOKEN_IN = exports.FIELD_EXPIRY = exports.FIELD_ARBITER = void 0;
|
|
4
|
+
// Field IDs matching BaseDataTypes.sol
|
|
5
|
+
exports.FIELD_ARBITER = 0;
|
|
6
|
+
exports.FIELD_EXPIRY = 1;
|
|
7
|
+
exports.FIELD_TOKEN_IN = 2;
|
|
8
|
+
exports.FIELD_RECIPIENT = 3;
|
|
9
|
+
exports.FIELD_FILL_EXPIRY = 4;
|
|
10
|
+
exports.FIELD_TOKEN_OUT = 5;
|
|
11
|
+
exports.FIELD_ORIGIN_OPS = 6;
|
|
12
|
+
exports.FIELD_DEST_OPS = 7;
|
|
13
|
+
// Field 8 is reserved in BaseDataTypes.sol
|
|
14
|
+
exports.FIELD_RECIPIENT_IS_SPONSOR = 9;
|
|
15
|
+
// Mode values
|
|
16
|
+
exports.MODE_CHECK_STORAGE = 1;
|
|
17
|
+
// Sentinel: allows any recipient address
|
|
18
|
+
exports.ANY_ADDRESS = '0xFFfFfFffFFfffFFfFFfFFFFFffFFFffffFfFFFfF';
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type Address, type Hex, type TypedDataDefinition } from 'viem';
|
|
2
|
-
import type { ProviderConfig, RhinestoneAccountConfig, RhinestoneConfig, Session, SessionEnableData } from '../../types';
|
|
2
|
+
import type { Policy, ProviderConfig, RhinestoneAccountConfig, RhinestoneConfig, Session, SessionEnableData } from '../../types';
|
|
3
3
|
import { type Module } from '../common';
|
|
4
4
|
import { SMART_SESSION_EMISSARY_ADDRESS, SMART_SESSION_EMISSARY_ADDRESS_DEV } from './core';
|
|
5
5
|
interface SessionData {
|
|
@@ -164,11 +164,21 @@ declare const SMART_SESSION_MODE_ENABLE = "0x01";
|
|
|
164
164
|
declare const SMART_SESSIONS_FALLBACK_TARGET_FLAG: Address;
|
|
165
165
|
declare const SMART_SESSIONS_FALLBACK_TARGET_SELECTOR_FLAG: Hex;
|
|
166
166
|
declare const SMART_SESSIONS_FALLBACK_TARGET_SELECTOR_FLAG_PERMITTED_TO_CALL_SMARTSESSION: Hex;
|
|
167
|
+
declare const DUMMY_PRECLAIMOP_TARGET: Address;
|
|
168
|
+
declare const DUMMY_PRECLAIMOP_SELECTOR: Hex;
|
|
169
|
+
declare const SPENDING_LIMITS_POLICY_ADDRESS: Address;
|
|
170
|
+
declare const TIME_FRAME_POLICY_ADDRESS: Address;
|
|
171
|
+
declare const SUDO_POLICY_ADDRESS: Address;
|
|
172
|
+
declare const UNIVERSAL_ACTION_POLICY_ADDRESS: Address;
|
|
173
|
+
declare const USAGE_LIMIT_POLICY_ADDRESS: Address;
|
|
174
|
+
declare const VALUE_LIMIT_POLICY_ADDRESS: Address;
|
|
175
|
+
declare const INTENT_EXECUTION_POLICY_ADDRESS: Address;
|
|
167
176
|
interface ResolvedSessionSignerSet {
|
|
168
177
|
type: 'experimental_session';
|
|
169
178
|
session: Session;
|
|
170
179
|
enableData?: SessionEnableData;
|
|
171
180
|
verifyExecutions: boolean;
|
|
181
|
+
claimPolicyData?: Hex;
|
|
172
182
|
}
|
|
173
183
|
declare function packSignature(signers: ResolvedSessionSignerSet, validatorSignature: Hex): Hex;
|
|
174
184
|
declare function getSessionDetails(account: Address, sessions: Session[], provider: ProviderConfig | undefined, useDevContracts?: boolean): Promise<SessionDetails>;
|
|
@@ -181,8 +191,9 @@ declare function getEnableSessionCall(account: Address, session: Session, enable
|
|
|
181
191
|
to: `0x${string}`;
|
|
182
192
|
data: `0x${string}`;
|
|
183
193
|
}>;
|
|
184
|
-
declare function getSessionData(session: Session): SessionData;
|
|
194
|
+
declare function getSessionData(session: Session, useDevContracts?: boolean): SessionData;
|
|
185
195
|
declare function getPermissionId(session: Session): `0x${string}`;
|
|
196
|
+
declare function getPolicyData(policy: Policy, useDevContracts?: boolean): PolicyData;
|
|
186
197
|
declare function getSmartSessionValidator(config: RhinestoneConfig): Module | null;
|
|
187
198
|
/**
|
|
188
199
|
* Builds a mockSignature for SSX validation gas estimation.
|
|
@@ -192,7 +203,7 @@ declare function getSmartSessionValidator(config: RhinestoneConfig): Module | nu
|
|
|
192
203
|
* The orchestrator slices off the first 20 bytes to identify the validator, then
|
|
193
204
|
* simulates verifyExecution with the mock emissary to estimate gas before the user signs.
|
|
194
205
|
*/
|
|
195
|
-
declare function buildMockSignature(session: Session, useDevContracts?: boolean, chainCount?: number): Hex;
|
|
196
|
-
export { SMART_SESSION_EMISSARY_ADDRESS, SMART_SESSION_EMISSARY_ADDRESS_DEV, SMART_SESSIONS_FALLBACK_TARGET_FLAG, SMART_SESSIONS_FALLBACK_TARGET_SELECTOR_FLAG, SMART_SESSIONS_FALLBACK_TARGET_SELECTOR_FLAG_PERMITTED_TO_CALL_SMARTSESSION, packSignature, getSessionData, getEnableSessionCall, getPermissionId, getSmartSessionValidator, getSessionDetails, isSessionEnabled, signEnableSession, buildMockSignature, };
|
|
206
|
+
declare function buildMockSignature(session: Session, useDevContracts?: boolean, chainCount?: number, targetChainId?: number): Hex;
|
|
207
|
+
export { SMART_SESSION_EMISSARY_ADDRESS, SMART_SESSION_EMISSARY_ADDRESS_DEV, SMART_SESSIONS_FALLBACK_TARGET_FLAG, SMART_SESSIONS_FALLBACK_TARGET_SELECTOR_FLAG, SMART_SESSIONS_FALLBACK_TARGET_SELECTOR_FLAG_PERMITTED_TO_CALL_SMARTSESSION, DUMMY_PRECLAIMOP_TARGET, DUMMY_PRECLAIMOP_SELECTOR, SPENDING_LIMITS_POLICY_ADDRESS, TIME_FRAME_POLICY_ADDRESS, SUDO_POLICY_ADDRESS, UNIVERSAL_ACTION_POLICY_ADDRESS, USAGE_LIMIT_POLICY_ADDRESS, VALUE_LIMIT_POLICY_ADDRESS, INTENT_EXECUTION_POLICY_ADDRESS, packSignature, getSessionData, getPolicyData, getEnableSessionCall, getPermissionId, getSmartSessionValidator, getSessionDetails, isSessionEnabled, signEnableSession, buildMockSignature, };
|
|
197
208
|
export type { ChainSession, ChainDigest, ResolvedSessionSignerSet, SessionData, SmartSessionModeType, SessionDetails, };
|
|
198
209
|
//# sourceMappingURL=smart-sessions.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"smart-sessions.d.ts","sourceRoot":"","sources":["../../../../modules/validators/smart-sessions.ts"],"names":[],"mappings":"AACA,OAAO,EACL,KAAK,OAAO,EAMZ,KAAK,GAAG,EAOR,KAAK,mBAAmB,EAKzB,MAAM,MAAM,CAAA;AAcb,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"smart-sessions.d.ts","sourceRoot":"","sources":["../../../../modules/validators/smart-sessions.ts"],"names":[],"mappings":"AACA,OAAO,EACL,KAAK,OAAO,EAMZ,KAAK,GAAG,EAOR,KAAK,mBAAmB,EAKzB,MAAM,MAAM,CAAA;AAcb,OAAO,KAAK,EAEV,MAAM,EACN,cAAc,EACd,u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