@charterlabs/rhinestone-sdk 0.3.9 → 0.4.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +89 -1
- package/dist/src/accounts/index.d.ts +6 -3
- 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.d.ts.map +1 -1
- package/dist/src/accounts/json-rpc/providers.js +3 -3
- package/dist/src/accounts/safe.d.ts.map +1 -1
- package/dist/src/accounts/safe.js +4 -1
- package/dist/src/accounts/signing/common.d.ts +10 -5
- package/dist/src/accounts/signing/common.d.ts.map +1 -1
- package/dist/src/accounts/signing/common.js +21 -7
- package/dist/src/accounts/signing/message.d.ts +3 -1
- package/dist/src/accounts/signing/message.d.ts.map +1 -1
- package/dist/src/accounts/signing/mfa-webauthn.d.ts +30 -0
- package/dist/src/accounts/signing/mfa-webauthn.d.ts.map +1 -0
- package/dist/src/accounts/signing/mfa-webauthn.js +119 -0
- package/dist/src/accounts/startale.js +1 -1
- package/dist/src/accounts/utils.d.ts +1 -1
- package/dist/src/accounts/utils.d.ts.map +1 -1
- package/dist/src/actions/mfa.d.ts +6 -2
- package/dist/src/actions/mfa.d.ts.map +1 -1
- package/dist/src/actions/mfa.js +14 -4
- 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/errors/index.d.ts +2 -2
- package/dist/src/errors/index.d.ts.map +1 -1
- package/dist/src/errors/index.js +2 -1
- package/dist/src/execution/error.d.ts +9 -1
- package/dist/src/execution/error.d.ts.map +1 -1
- package/dist/src/execution/error.js +12 -1
- package/dist/src/execution/index.d.ts +6 -4
- package/dist/src/execution/index.d.ts.map +1 -1
- package/dist/src/execution/index.js +17 -13
- package/dist/src/execution/utils.d.ts +17 -6
- package/dist/src/execution/utils.d.ts.map +1 -1
- package/dist/src/execution/utils.js +193 -43
- package/dist/src/index.d.ts +5 -5
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +13 -11
- 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/core.d.ts +6 -2
- package/dist/src/modules/validators/core.d.ts.map +1 -1
- package/dist/src/modules/validators/core.js +46 -21
- 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 +5 -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 +22 -7
- package/dist/src/modules/validators/smart-sessions.d.ts.map +1 -1
- package/dist/src/modules/validators/smart-sessions.js +82 -22
- 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 +2 -1
- package/dist/src/orchestrator/registry.d.ts.map +1 -1
- package/dist/src/orchestrator/registry.js +17 -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 +88 -5
- package/dist/src/types.d.ts.map +1 -1
- package/dist/src/utils/index.d.ts +3 -9
- package/dist/src/utils/index.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 -118
- 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 -150
- 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/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,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createExpressRouter = createExpressRouter;
|
|
4
|
+
const handlers_1 = require("./handlers");
|
|
5
|
+
function createExpressRouter(config) {
|
|
6
|
+
// Dynamic import avoidance: we type the router interface manually
|
|
7
|
+
// so express doesn't need to be installed unless this function is called.
|
|
8
|
+
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
9
|
+
const { Router } = require('express');
|
|
10
|
+
const router = Router();
|
|
11
|
+
const handleAccessToken = (0, handlers_1.createCoreAccessTokenHandler)(config);
|
|
12
|
+
const handleExtensionToken = (0, handlers_1.createCoreExtensionTokenHandler)(config);
|
|
13
|
+
router.get('/access-token', async (_req, res) => {
|
|
14
|
+
const result = await handleAccessToken();
|
|
15
|
+
res.status(result.status).json(result.body);
|
|
16
|
+
});
|
|
17
|
+
router.post('/extension-token', async (req, res) => {
|
|
18
|
+
const body = req.body;
|
|
19
|
+
const intentInput = body?.intentInput;
|
|
20
|
+
const result = await handleExtensionToken(intentInput);
|
|
21
|
+
res.status(result.status).json(result.body);
|
|
22
|
+
});
|
|
23
|
+
return router;
|
|
24
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { type JwtSignerConfig } from './signer';
|
|
2
|
+
export type JwtHandlerConfig = JwtSignerConfig;
|
|
3
|
+
interface HandlerResult {
|
|
4
|
+
status: number;
|
|
5
|
+
body: Record<string, unknown>;
|
|
6
|
+
}
|
|
7
|
+
export declare function createCoreAccessTokenHandler(config: JwtHandlerConfig): () => Promise<HandlerResult>;
|
|
8
|
+
export declare function createCoreExtensionTokenHandler(config: JwtHandlerConfig): (intentInput: unknown) => Promise<HandlerResult>;
|
|
9
|
+
export {};
|
|
10
|
+
//# sourceMappingURL=handlers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"handlers.d.ts","sourceRoot":"","sources":["../../../jwt-server/handlers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAmB,KAAK,eAAe,EAAE,MAAM,UAAU,CAAA;AAGhE,MAAM,MAAM,gBAAgB,GAAG,eAAe,CAAA;AAE9C,UAAU,aAAa;IACrB,MAAM,EAAE,MAAM,CAAA;IACd,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;CAC9B;AAED,wBAAgB,4BAA4B,CAC1C,MAAM,EAAE,gBAAgB,GACvB,MAAM,OAAO,CAAC,aAAa,CAAC,CAa9B;AAED,wBAAgB,+BAA+B,CAC7C,MAAM,EAAE,gBAAgB,GACvB,CAAC,WAAW,EAAE,OAAO,KAAK,OAAO,CAAC,aAAa,CAAC,CAuBlD"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createCoreAccessTokenHandler = createCoreAccessTokenHandler;
|
|
4
|
+
exports.createCoreExtensionTokenHandler = createCoreExtensionTokenHandler;
|
|
5
|
+
const signer_1 = require("./signer");
|
|
6
|
+
const sponsorship_1 = require("./sponsorship");
|
|
7
|
+
function createCoreAccessTokenHandler(config) {
|
|
8
|
+
const signer = (0, signer_1.createJwtSigner)(config);
|
|
9
|
+
return async () => {
|
|
10
|
+
try {
|
|
11
|
+
const token = await signer.accessToken();
|
|
12
|
+
return { status: 200, body: { token } };
|
|
13
|
+
}
|
|
14
|
+
catch (error) {
|
|
15
|
+
const message = error instanceof Error ? error.message : 'Internal server error';
|
|
16
|
+
return { status: 500, body: { error: message } };
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
function createCoreExtensionTokenHandler(config) {
|
|
21
|
+
const signer = (0, signer_1.createJwtSigner)(config);
|
|
22
|
+
return async (intentInput) => {
|
|
23
|
+
if (intentInput === undefined || intentInput === null) {
|
|
24
|
+
return {
|
|
25
|
+
status: 400,
|
|
26
|
+
body: { error: 'Missing intentInput in request body' },
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
try {
|
|
30
|
+
const token = await signer.getIntentExtensionToken(intentInput);
|
|
31
|
+
return { status: 200, body: { token } };
|
|
32
|
+
}
|
|
33
|
+
catch (error) {
|
|
34
|
+
if (error instanceof sponsorship_1.SponsorshipDeniedError) {
|
|
35
|
+
return { status: 403, body: { error: error.message } };
|
|
36
|
+
}
|
|
37
|
+
const message = error instanceof Error ? error.message : 'Internal server error';
|
|
38
|
+
return { status: 500, body: { error: message } };
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export { computeIntentInputDigest } from './digest';
|
|
2
|
+
export { createExpressRouter } from './express';
|
|
3
|
+
export type { JwtHandlerConfig } from './handlers';
|
|
4
|
+
export { jcsCanonicalise } from './jcs';
|
|
5
|
+
export { createJwtSigner, type JwtCredentials, type JwtSignerConfig, } from './signer';
|
|
6
|
+
export { SponsorshipDeniedError, type SponsorshipFilter, shouldSponsor, } from './sponsorship';
|
|
7
|
+
export { createAccessTokenHandler, createExtensionTokenHandler, } from './web';
|
|
8
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../jwt-server/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,wBAAwB,EAAE,MAAM,UAAU,CAAA;AACnD,OAAO,EAAE,mBAAmB,EAAE,MAAM,WAAW,CAAA;AAC/C,YAAY,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAA;AAClD,OAAO,EAAE,eAAe,EAAE,MAAM,OAAO,CAAA;AACvC,OAAO,EACL,eAAe,EACf,KAAK,cAAc,EACnB,KAAK,eAAe,GACrB,MAAM,UAAU,CAAA;AACjB,OAAO,EACL,sBAAsB,EACtB,KAAK,iBAAiB,EACtB,aAAa,GACd,MAAM,eAAe,CAAA;AACtB,OAAO,EACL,wBAAwB,EACxB,2BAA2B,GAC5B,MAAM,OAAO,CAAA"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createExtensionTokenHandler = exports.createAccessTokenHandler = exports.shouldSponsor = exports.SponsorshipDeniedError = exports.createJwtSigner = exports.jcsCanonicalise = exports.createExpressRouter = exports.computeIntentInputDigest = void 0;
|
|
4
|
+
// biome-ignore lint/performance/noBarrelFile: subpath entry point for @rhinestone/sdk/jwt-server
|
|
5
|
+
var digest_1 = require("./digest");
|
|
6
|
+
Object.defineProperty(exports, "computeIntentInputDigest", { enumerable: true, get: function () { return digest_1.computeIntentInputDigest; } });
|
|
7
|
+
var express_1 = require("./express");
|
|
8
|
+
Object.defineProperty(exports, "createExpressRouter", { enumerable: true, get: function () { return express_1.createExpressRouter; } });
|
|
9
|
+
var jcs_1 = require("./jcs");
|
|
10
|
+
Object.defineProperty(exports, "jcsCanonicalise", { enumerable: true, get: function () { return jcs_1.jcsCanonicalise; } });
|
|
11
|
+
var signer_1 = require("./signer");
|
|
12
|
+
Object.defineProperty(exports, "createJwtSigner", { enumerable: true, get: function () { return signer_1.createJwtSigner; } });
|
|
13
|
+
var sponsorship_1 = require("./sponsorship");
|
|
14
|
+
Object.defineProperty(exports, "SponsorshipDeniedError", { enumerable: true, get: function () { return sponsorship_1.SponsorshipDeniedError; } });
|
|
15
|
+
Object.defineProperty(exports, "shouldSponsor", { enumerable: true, get: function () { return sponsorship_1.shouldSponsor; } });
|
|
16
|
+
var web_1 = require("./web");
|
|
17
|
+
Object.defineProperty(exports, "createAccessTokenHandler", { enumerable: true, get: function () { return web_1.createAccessTokenHandler; } });
|
|
18
|
+
Object.defineProperty(exports, "createExtensionTokenHandler", { enumerable: true, get: function () { return web_1.createExtensionTokenHandler; } });
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* RFC 8785 JSON Canonicalization Scheme (JCS).
|
|
3
|
+
*
|
|
4
|
+
* Produces a deterministic JSON serialization by:
|
|
5
|
+
* 1. Sorting object keys lexicographically (Unicode code-point order)
|
|
6
|
+
* 2. Using ES2015+ `JSON.stringify` number serialization (IEEE 754 → shortest round-trip)
|
|
7
|
+
* 3. No whitespace
|
|
8
|
+
*
|
|
9
|
+
* Reference: https://www.rfc-editor.org/rfc/rfc8785
|
|
10
|
+
*/
|
|
11
|
+
export declare function jcsCanonicalise(value: unknown): string;
|
|
12
|
+
//# sourceMappingURL=jcs.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"jcs.d.ts","sourceRoot":"","sources":["../../../jwt-server/jcs.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,wBAAgB,eAAe,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAEtD"}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* RFC 8785 JSON Canonicalization Scheme (JCS).
|
|
4
|
+
*
|
|
5
|
+
* Produces a deterministic JSON serialization by:
|
|
6
|
+
* 1. Sorting object keys lexicographically (Unicode code-point order)
|
|
7
|
+
* 2. Using ES2015+ `JSON.stringify` number serialization (IEEE 754 → shortest round-trip)
|
|
8
|
+
* 3. No whitespace
|
|
9
|
+
*
|
|
10
|
+
* Reference: https://www.rfc-editor.org/rfc/rfc8785
|
|
11
|
+
*/
|
|
12
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
exports.jcsCanonicalise = jcsCanonicalise;
|
|
14
|
+
function jcsCanonicalise(value) {
|
|
15
|
+
return serialize(value);
|
|
16
|
+
}
|
|
17
|
+
function serialize(value) {
|
|
18
|
+
if (value === null || value === undefined) {
|
|
19
|
+
return 'null';
|
|
20
|
+
}
|
|
21
|
+
switch (typeof value) {
|
|
22
|
+
case 'boolean':
|
|
23
|
+
return value ? 'true' : 'false';
|
|
24
|
+
case 'number':
|
|
25
|
+
if (!Number.isFinite(value)) {
|
|
26
|
+
throw new Error(`JCS: non-finite number: ${value}`);
|
|
27
|
+
}
|
|
28
|
+
// ES2015 Number-to-String satisfies RFC 8785 §3.2.2.3
|
|
29
|
+
return Object.is(value, -0) ? '0' : String(value);
|
|
30
|
+
case 'string':
|
|
31
|
+
return JSON.stringify(value);
|
|
32
|
+
case 'bigint':
|
|
33
|
+
// BigInt is not valid JSON; coerce to bare decimal string.
|
|
34
|
+
// Values above MAX_SAFE_INTEGER are rejected because downstream
|
|
35
|
+
// JSON parsers using IEEE 754 doubles would silently lose precision,
|
|
36
|
+
// producing a different digest.
|
|
37
|
+
if (value > BigInt(Number.MAX_SAFE_INTEGER) ||
|
|
38
|
+
value < BigInt(-Number.MAX_SAFE_INTEGER)) {
|
|
39
|
+
throw new Error(`JCS: BigInt ${value} exceeds safe integer range — convert to string before calling`);
|
|
40
|
+
}
|
|
41
|
+
return String(value);
|
|
42
|
+
default:
|
|
43
|
+
break;
|
|
44
|
+
}
|
|
45
|
+
if (Array.isArray(value)) {
|
|
46
|
+
const items = value.map((item) => serialize(item));
|
|
47
|
+
return `[${items.join(',')}]`;
|
|
48
|
+
}
|
|
49
|
+
// Object — sort keys by Unicode code-point order
|
|
50
|
+
const obj = value;
|
|
51
|
+
const keys = Object.keys(obj).sort();
|
|
52
|
+
const members = [];
|
|
53
|
+
for (const key of keys) {
|
|
54
|
+
const v = obj[key];
|
|
55
|
+
if (v === undefined)
|
|
56
|
+
continue; // skip undefined properties
|
|
57
|
+
members.push(`${JSON.stringify(key)}:${serialize(v)}`);
|
|
58
|
+
}
|
|
59
|
+
return `{${members.join(',')}}`;
|
|
60
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { type SponsorshipFilter } from './sponsorship';
|
|
2
|
+
export interface JwtCredentials {
|
|
3
|
+
privateKey: JsonWebKey;
|
|
4
|
+
integratorId: string;
|
|
5
|
+
projectId: string;
|
|
6
|
+
appId: string;
|
|
7
|
+
keyId: string;
|
|
8
|
+
audience?: string;
|
|
9
|
+
}
|
|
10
|
+
export interface JwtSignerConfig {
|
|
11
|
+
jwt: JwtCredentials;
|
|
12
|
+
shouldSponsor?: SponsorshipFilter;
|
|
13
|
+
}
|
|
14
|
+
export declare function createJwtSigner(config: JwtSignerConfig): {
|
|
15
|
+
accessToken: () => Promise<string>;
|
|
16
|
+
getIntentExtensionToken: (intentInput: unknown) => Promise<string>;
|
|
17
|
+
};
|
|
18
|
+
//# sourceMappingURL=signer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"signer.d.ts","sourceRoot":"","sources":["../../../jwt-server/signer.ts"],"names":[],"mappings":"AAEA,OAAO,EAGL,KAAK,iBAAiB,EACvB,MAAM,eAAe,CAAA;AAEtB,MAAM,WAAW,cAAc;IAC7B,UAAU,EAAE,UAAU,CAAA;IACtB,YAAY,EAAE,MAAM,CAAA;IACpB,SAAS,EAAE,MAAM,CAAA;IACjB,KAAK,EAAE,MAAM,CAAA;IACb,KAAK,EAAE,MAAM,CAAA;IACb,QAAQ,CAAC,EAAE,MAAM,CAAA;CAClB;AAED,MAAM,WAAW,eAAe;IAC9B,GAAG,EAAE,cAAc,CAAA;IACnB,aAAa,CAAC,EAAE,iBAAiB,CAAA;CAClC;AAeD,wBAAgB,eAAe,CAAC,MAAM,EAAE,eAAe,GAAG;IACxD,WAAW,EAAE,MAAM,OAAO,CAAC,MAAM,CAAC,CAAA;IAClC,uBAAuB,EAAE,CAAC,WAAW,EAAE,OAAO,KAAK,OAAO,CAAC,MAAM,CAAC,CAAA;CACnE,CAoEA"}
|
|
@@ -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
|
+
}
|
|
@@ -12,6 +12,9 @@ interface WebauthnCredential {
|
|
|
12
12
|
pubKey: PublicKey | Hex | Uint8Array;
|
|
13
13
|
authenticatorId: string;
|
|
14
14
|
}
|
|
15
|
+
type MultiFactorValidatorDataOptions = {
|
|
16
|
+
useWebAuthnPrecompile?: boolean;
|
|
17
|
+
};
|
|
15
18
|
declare const OWNABLE_VALIDATOR_ADDRESS: Address;
|
|
16
19
|
declare const ENS_VALIDATOR_ADDRESS: Address;
|
|
17
20
|
declare const WEBAUTHN_VALIDATOR_ADDRESS: Address;
|
|
@@ -23,9 +26,10 @@ declare function getValidator(owners: OwnerSet): Module;
|
|
|
23
26
|
declare function getOwnableValidator(threshold: number, owners: Address[], address?: Address): Module;
|
|
24
27
|
declare function getENSValidator(threshold: number, owners: Address[], ownerExpirations: number[], address?: Address): Module;
|
|
25
28
|
declare function getWebAuthnValidator(threshold: number, webAuthnCredentials: WebauthnCredential[], address?: Address): Module;
|
|
26
|
-
declare function
|
|
29
|
+
declare function getMultiFactorSubValidatorData(validator: OwnableValidatorConfig | ENSValidatorConfig | WebauthnValidatorConfig, options?: MultiFactorValidatorDataOptions): Hex;
|
|
30
|
+
declare function getMultiFactorValidator(threshold: number, validators: (OwnableValidatorConfig | ENSValidatorConfig | WebauthnValidatorConfig | null)[], options?: MultiFactorValidatorDataOptions): Module;
|
|
27
31
|
declare function getSocialRecoveryValidator(guardians: Account[], threshold?: number): Module;
|
|
28
32
|
declare function supportsEip712(validator: Module): boolean;
|
|
29
|
-
export { OWNABLE_VALIDATOR_ADDRESS, ENS_VALIDATOR_ADDRESS, WEBAUTHN_VALIDATOR_ADDRESS, MULTI_FACTOR_VALIDATOR_ADDRESS, WEBAUTHN_V0_VALIDATOR_ADDRESS, SMART_SESSION_EMISSARY_ADDRESS, SMART_SESSION_EMISSARY_ADDRESS_DEV, getOwnerValidator, getOwnableValidator, getENSValidator, getWebAuthnValidator, getMultiFactorValidator, getSocialRecoveryValidator, getValidator, getMockSignature, supportsEip712, };
|
|
33
|
+
export { OWNABLE_VALIDATOR_ADDRESS, ENS_VALIDATOR_ADDRESS, WEBAUTHN_VALIDATOR_ADDRESS, MULTI_FACTOR_VALIDATOR_ADDRESS, WEBAUTHN_V0_VALIDATOR_ADDRESS, SMART_SESSION_EMISSARY_ADDRESS, SMART_SESSION_EMISSARY_ADDRESS_DEV, getOwnerValidator, getOwnableValidator, getENSValidator, getWebAuthnValidator, getMultiFactorValidator, getSocialRecoveryValidator, getValidator, getMockSignature, getMultiFactorSubValidatorData, supportsEip712, };
|
|
30
34
|
export type { WebauthnCredential };
|
|
31
35
|
//# sourceMappingURL=core.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"core.d.ts","sourceRoot":"","sources":["../../../../modules/validators/core.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,OAAO,EACZ,KAAK,OAAO,EAKZ,KAAK,GAAG,EAKT,MAAM,MAAM,CAAA;
|
|
1
|
+
{"version":3,"file":"core.d.ts","sourceRoot":"","sources":["../../../../modules/validators/core.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,OAAO,EACZ,KAAK,OAAO,EAKZ,KAAK,GAAG,EAKT,MAAM,MAAM,CAAA;AAOb,OAAO,KAAK,EACV,kBAAkB,EAClB,sBAAsB,EACtB,QAAQ,EACR,uBAAuB,EACvB,uBAAuB,EACxB,MAAM,aAAa,CAAA;AAEpB,OAAO,EAA4B,KAAK,MAAM,EAAE,MAAM,WAAW,CAAA;AAEjE,QAAA,MAAM,kCAAkC,EAAE,OACI,CAAA;AAC9C,QAAA,MAAM,8BAA8B,EAAE,OACQ,CAAA;AAE9C,UAAU,SAAS;IACjB,MAAM,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;IAC3B,CAAC,EAAE,MAAM,CAAA;IACT,CAAC,EAAE,MAAM,CAAA;CACV;AAED,UAAU,kBAAkB;IAC1B,MAAM,EAAE,SAAS,GAAG,GAAG,GAAG,UAAU,CAAA;IACpC,eAAe,EAAE,MAAM,CAAA;CACxB;AAED,KAAK,+BAA+B,GAAG;IACrC,qBAAqB,CAAC,EAAE,OAAO,CAAA;CAChC,CAAA;AAED,QAAA,MAAM,yBAAyB,EAAE,OACa,CAAA;AAC9C,QAAA,MAAM,qBAAqB,EAAE,OACiB,CAAA;AAC9C,QAAA,MAAM,0BAA0B,EAAE,OACY,CAAA;AAG9C,QAAA,MAAM,8BAA8B,EAAE,OACQ,CAAA;AAO9C,QAAA,MAAM,6BAA6B,EAAE,OACS,CAAA;AAO9C,iBAAS,iBAAiB,CAAC,MAAM,EAAE,uBAAuB,UAKzD;AAED,iBAAS,gBAAgB,CAAC,QAAQ,EAAE,QAAQ,GAAG,GAAG,CAwDjD;AAED,iBAAS,YAAY,CAAC,MAAM,EAAE,QAAQ,UA2BrC;AAsBD,iBAAS,mBAAmB,CAC1B,SAAS,EAAE,MAAM,EACjB,MAAM,EAAE,OAAO,EAAE,EACjB,OAAO,CAAC,EAAE,OAAO,GAChB,MAAM,CAiBR;AAED,iBAAS,eAAe,CACtB,SAAS,EAAE,MAAM,EACjB,MAAM,EAAE,OAAO,EAAE,EACjB,gBAAgB,EAAE,MAAM,EAAE,EAC1B,OAAO,CAAC,EAAE,OAAO,GAChB,MAAM,CAsCR;AAED,iBAAS,oBAAoB,CAC3B,SAAS,EAAE,MAAM,EACjB,mBAAmB,EAAE,kBAAkB,EAAE,EACzC,OAAO,CAAC,EAAE,OAAO,GAChB,MAAM,CAwCR;AAqBD,iBAAS,8BAA8B,CACrC,SAAS,EACL,sBAAsB,GACtB,kBAAkB,GAClB,uBAAuB,EAC3B,OAAO,GAAE,+BAAoC,GAC5C,GAAG,CAaL;AAED,iBAAS,uBAAuB,CAC9B,SAAS,EAAE,MAAM,EACjB,UAAU,EAAE,CACR,sBAAsB,GACtB,kBAAkB,GAClB,uBAAuB,GACvB,IAAI,CACP,EAAE,EACH,OAAO,GAAE,+BAAoC,GAC5C,MAAM,CAgDR;AAED,iBAAS,0BAA0B,CACjC,SAAS,EAAE,OAAO,EAAE,EACpB,SAAS,SAAI,GACZ,MAAM,CAsBR;AAeD,iBAAS,cAAc,CAAC,SAAS,EAAE,MAAM,WAUxC;AAED,OAAO,EACL,yBAAyB,EACzB,qBAAqB,EACrB,0BAA0B,EAC1B,8BAA8B,EAC9B,6BAA6B,EAC7B,8BAA8B,EAC9B,kCAAkC,EAClC,iBAAiB,EACjB,mBAAmB,EACnB,eAAe,EACf,oBAAoB,EACpB,uBAAuB,EACvB,0BAA0B,EAC1B,YAAY,EACZ,gBAAgB,EAChB,8BAA8B,EAC9B,cAAc,GACf,CAAA;AACD,YAAY,EAAE,kBAAkB,EAAE,CAAA"}
|
|
@@ -9,9 +9,11 @@ exports.getMultiFactorValidator = getMultiFactorValidator;
|
|
|
9
9
|
exports.getSocialRecoveryValidator = getSocialRecoveryValidator;
|
|
10
10
|
exports.getValidator = getValidator;
|
|
11
11
|
exports.getMockSignature = getMockSignature;
|
|
12
|
+
exports.getMultiFactorSubValidatorData = getMultiFactorSubValidatorData;
|
|
12
13
|
exports.supportsEip712 = supportsEip712;
|
|
13
14
|
const viem_1 = require("viem");
|
|
14
15
|
const error_1 = require("../../accounts/error");
|
|
16
|
+
const mfa_webauthn_1 = require("../../accounts/signing/mfa-webauthn");
|
|
15
17
|
const common_1 = require("../common");
|
|
16
18
|
const SMART_SESSION_EMISSARY_ADDRESS_DEV = '0x60731de80d78548875f8a67c4fec2a8660194e0c';
|
|
17
19
|
exports.SMART_SESSION_EMISSARY_ADDRESS_DEV = SMART_SESSION_EMISSARY_ADDRESS_DEV;
|
|
@@ -53,7 +55,9 @@ function getMockSignature(ownerSet) {
|
|
|
53
55
|
case 'multi-factor': {
|
|
54
56
|
const mockValidators = ownerSet.validators.map((validator, index) => {
|
|
55
57
|
const validatorModule = getValidator(validator);
|
|
56
|
-
const signature =
|
|
58
|
+
const signature = validator.type === 'passkey'
|
|
59
|
+
? (0, mfa_webauthn_1.extractMfaWebAuthnSignatureFromPasskeySignature)(getMockSignature(validator))
|
|
60
|
+
: getMockSignature(validator);
|
|
57
61
|
return {
|
|
58
62
|
packedValidatorAndId: (0, viem_1.encodePacked)(['bytes12', 'address'], [
|
|
59
63
|
(0, viem_1.pad)((0, viem_1.toHex)(index), {
|
|
@@ -97,6 +101,22 @@ function getValidator(owners) {
|
|
|
97
101
|
}
|
|
98
102
|
}
|
|
99
103
|
}
|
|
104
|
+
function getPublicKey(webAuthnCredential) {
|
|
105
|
+
if (typeof webAuthnCredential.pubKey === 'string' ||
|
|
106
|
+
webAuthnCredential.pubKey instanceof Uint8Array) {
|
|
107
|
+
// It's a P256Credential
|
|
108
|
+
const { x, y, prefix } = parsePublicKey(webAuthnCredential.pubKey);
|
|
109
|
+
if (prefix && prefix !== 4) {
|
|
110
|
+
throw new Error('Only uncompressed public keys are supported');
|
|
111
|
+
}
|
|
112
|
+
return {
|
|
113
|
+
x,
|
|
114
|
+
y,
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
// It's already a PublicKey
|
|
118
|
+
return webAuthnCredential.pubKey;
|
|
119
|
+
}
|
|
100
120
|
function getOwnableValidator(threshold, owners, address) {
|
|
101
121
|
return {
|
|
102
122
|
address: address ?? OWNABLE_VALIDATOR_ADDRESS,
|
|
@@ -143,24 +163,6 @@ function getENSValidator(threshold, owners, ownerExpirations, address) {
|
|
|
143
163
|
};
|
|
144
164
|
}
|
|
145
165
|
function getWebAuthnValidator(threshold, webAuthnCredentials, address) {
|
|
146
|
-
function getPublicKey(webAuthnCredential) {
|
|
147
|
-
if (typeof webAuthnCredential.pubKey === 'string' ||
|
|
148
|
-
webAuthnCredential.pubKey instanceof Uint8Array) {
|
|
149
|
-
// It's a P256Credential
|
|
150
|
-
const { x, y, prefix } = parsePublicKey(webAuthnCredential.pubKey);
|
|
151
|
-
if (prefix && prefix !== 4) {
|
|
152
|
-
throw new Error('Only uncompressed public keys are supported');
|
|
153
|
-
}
|
|
154
|
-
return {
|
|
155
|
-
x,
|
|
156
|
-
y,
|
|
157
|
-
};
|
|
158
|
-
}
|
|
159
|
-
else {
|
|
160
|
-
// It's already a PublicKey
|
|
161
|
-
return webAuthnCredential.pubKey;
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
166
|
const publicKeys = webAuthnCredentials.map(getPublicKey);
|
|
165
167
|
return {
|
|
166
168
|
address: address ?? WEBAUTHN_VALIDATOR_ADDRESS,
|
|
@@ -197,7 +199,30 @@ function getWebAuthnValidator(threshold, webAuthnCredentials, address) {
|
|
|
197
199
|
type: common_1.MODULE_TYPE_ID_VALIDATOR,
|
|
198
200
|
};
|
|
199
201
|
}
|
|
200
|
-
function
|
|
202
|
+
function getWebAuthnMfaValidatorData(threshold, webAuthnCredentials, options = {}) {
|
|
203
|
+
return (0, mfa_webauthn_1.encodeMfaWebAuthnValidatorData)({
|
|
204
|
+
usePrecompile: options.useWebAuthnPrecompile ?? false,
|
|
205
|
+
threshold,
|
|
206
|
+
credentials: webAuthnCredentials.map((credential) => {
|
|
207
|
+
const publicKey = getPublicKey(credential);
|
|
208
|
+
return {
|
|
209
|
+
pubKeyX: publicKey.x,
|
|
210
|
+
pubKeyY: publicKey.y,
|
|
211
|
+
requireUV: false,
|
|
212
|
+
};
|
|
213
|
+
}),
|
|
214
|
+
});
|
|
215
|
+
}
|
|
216
|
+
function getMultiFactorSubValidatorData(validator, options = {}) {
|
|
217
|
+
if (validator.type === 'passkey') {
|
|
218
|
+
return getWebAuthnMfaValidatorData(validator.threshold ?? 1, validator.accounts.map((account) => ({
|
|
219
|
+
pubKey: account.publicKey,
|
|
220
|
+
authenticatorId: account.id,
|
|
221
|
+
})), options);
|
|
222
|
+
}
|
|
223
|
+
return getValidator(validator).initData;
|
|
224
|
+
}
|
|
225
|
+
function getMultiFactorValidator(threshold, validators, options = {}) {
|
|
201
226
|
return {
|
|
202
227
|
address: MULTI_FACTOR_VALIDATOR_ADDRESS,
|
|
203
228
|
initData: (0, viem_1.encodePacked)(['uint8', 'bytes'], [
|
|
@@ -229,7 +254,7 @@ function getMultiFactorValidator(threshold, validators) {
|
|
|
229
254
|
}),
|
|
230
255
|
validatorModule.address,
|
|
231
256
|
]),
|
|
232
|
-
data:
|
|
257
|
+
data: getMultiFactorSubValidatorData(validator, options),
|
|
233
258
|
};
|
|
234
259
|
})
|
|
235
260
|
.filter((validator) => validator !== null),
|
|
@@ -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 } 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, };
|
|
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,
|
|
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.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,6 +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; } });
|
|
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
|