@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
|
@@ -29,15 +29,18 @@ const accounts_1 = require("../accounts");
|
|
|
29
29
|
const common_1 = require("../accounts/signing/common");
|
|
30
30
|
const startale_1 = require("../accounts/startale");
|
|
31
31
|
const utils_1 = require("../accounts/utils");
|
|
32
|
+
const provider_1 = require("../auth/provider");
|
|
32
33
|
const modules_1 = require("../modules");
|
|
33
34
|
const validators_1 = require("../modules/validators");
|
|
34
35
|
const core_1 = require("../modules/validators/core");
|
|
36
|
+
const permit2_1 = require("../modules/validators/policies/claim/permit2");
|
|
35
37
|
const orchestrator_1 = require("../orchestrator");
|
|
36
38
|
const registry_1 = require("../orchestrator/registry");
|
|
37
39
|
const types_1 = require("../orchestrator/types");
|
|
40
|
+
const utils_2 = require("../orchestrator/utils");
|
|
38
41
|
const compact_1 = require("./compact");
|
|
39
42
|
const error_1 = require("./error");
|
|
40
|
-
const
|
|
43
|
+
const permit2_2 = require("./permit2");
|
|
41
44
|
const singleChainOps_1 = require("./singleChainOps");
|
|
42
45
|
function isResolvedSessionSignerSet(signers) {
|
|
43
46
|
return (signers?.type === 'experimental_session' && 'verifyExecutions' in signers);
|
|
@@ -49,11 +52,13 @@ async function resolveSignersForChain(config, signers, chainId) {
|
|
|
49
52
|
const resolved = resolveSessionForChain(signers, chainId);
|
|
50
53
|
const enabled = await (0, validators_1.isSessionEnabled)((0, accounts_1.getAddress)(config), config.provider, resolved.session, config.useDevContracts);
|
|
51
54
|
const enableData = enabled ? undefined : resolved.enableData;
|
|
55
|
+
const hasExplicitActions = !!resolved.session.actions?.length;
|
|
56
|
+
const verifyExecutions = resolved.verifyExecutions ?? signers.verifyExecutions ?? hasExplicitActions;
|
|
52
57
|
return {
|
|
53
58
|
type: 'experimental_session',
|
|
54
59
|
session: resolved.session,
|
|
55
60
|
enableData,
|
|
56
|
-
verifyExecutions
|
|
61
|
+
verifyExecutions,
|
|
57
62
|
};
|
|
58
63
|
}
|
|
59
64
|
function resolveSessionForChain(signers, chainId) {
|
|
@@ -73,9 +78,10 @@ async function prepareTransaction(config, transaction) {
|
|
|
73
78
|
if (isUserOpSigner) {
|
|
74
79
|
throw new error_1.SignerNotSupportedError();
|
|
75
80
|
}
|
|
76
|
-
const
|
|
81
|
+
const prepared = await prepareTransactionAsIntent(config, sourceChains, targetChain, await resolveCallInputs(transaction.calls, config, targetChain, accountAddress), transaction.gasLimit, tokenRequests, recipient, sponsored, eip7702InitSignature, settlementLayers, sourceAssets, feeAsset, lockFunds, auxiliaryFunds, account, signers);
|
|
77
82
|
return {
|
|
78
|
-
intentRoute,
|
|
83
|
+
intentRoute: prepared.intentRoute,
|
|
84
|
+
intentInput: prepared.intentInput,
|
|
79
85
|
transaction,
|
|
80
86
|
};
|
|
81
87
|
}
|
|
@@ -124,6 +130,7 @@ async function signTransaction(config, preparedTransaction) {
|
|
|
124
130
|
const targetExecutionSignature = await getTargetExecutionSignature(config, intentRoute.intentOp, targetChain, signers);
|
|
125
131
|
return {
|
|
126
132
|
intentRoute,
|
|
133
|
+
intentInput: preparedTransaction.intentInput,
|
|
127
134
|
transaction: preparedTransaction.transaction,
|
|
128
135
|
originSignatures,
|
|
129
136
|
destinationSignature,
|
|
@@ -134,7 +141,16 @@ async function getTargetExecutionSignature(config, intentOp, targetChain, signer
|
|
|
134
141
|
if (signers?.type !== 'experimental_session') {
|
|
135
142
|
return undefined;
|
|
136
143
|
}
|
|
144
|
+
const settlementLayers = intentOp.elements.map((e) => e.mandate.qualifier.settlementContext.settlementLayer);
|
|
145
|
+
const hasIntentExecutorOps = settlementLayers.some((l) => l === 'INTENT_EXECUTOR' || l === 'SAME_CHAIN');
|
|
146
|
+
if (!hasIntentExecutorOps) {
|
|
147
|
+
return undefined;
|
|
148
|
+
}
|
|
137
149
|
const resolvedSigners = await resolveSignersForChain(config, signers, targetChain.id);
|
|
150
|
+
if (!isResolvedSessionSignerSet(resolvedSigners) ||
|
|
151
|
+
!resolvedSigners.verifyExecutions) {
|
|
152
|
+
return undefined;
|
|
153
|
+
}
|
|
138
154
|
const destination = getTargetExecutionMessage(config, intentOp);
|
|
139
155
|
const validator = getValidator(config, signers);
|
|
140
156
|
if (!validator) {
|
|
@@ -281,10 +297,10 @@ async function signAuthorizationsInternal(config, data) {
|
|
|
281
297
|
return authorizations;
|
|
282
298
|
}
|
|
283
299
|
async function submitTransaction(config, signedTransaction, authorizations, dryRun = false) {
|
|
284
|
-
const { intentRoute, transaction, originSignatures, destinationSignature, targetExecutionSignature, } = signedTransaction;
|
|
300
|
+
const { intentRoute, intentInput, transaction, originSignatures, destinationSignature, targetExecutionSignature, } = signedTransaction;
|
|
285
301
|
const { sourceChains, targetChain } = getTransactionParams(transaction);
|
|
286
302
|
const intentOp = intentRoute.intentOp;
|
|
287
|
-
return await submitIntent(config, sourceChains, targetChain, intentOp, originSignatures, destinationSignature, targetExecutionSignature, authorizations, dryRun);
|
|
303
|
+
return await submitIntent(config, sourceChains, targetChain, intentOp, originSignatures, destinationSignature, targetExecutionSignature, authorizations, dryRun, intentInput);
|
|
288
304
|
}
|
|
289
305
|
async function submitUserOperation(config, signedUserOperation) {
|
|
290
306
|
const chain = signedUserOperation.transaction.chain;
|
|
@@ -398,13 +414,50 @@ async function prepareTransactionAsIntent(config, sourceChains, targetChain, cal
|
|
|
398
414
|
const intentAccount = {
|
|
399
415
|
...getIntentAccount(config, eip7702InitSignature, account),
|
|
400
416
|
...(signers?.type === 'experimental_session' && {
|
|
401
|
-
|
|
417
|
+
// Global fallback: target-chain sig for backward-compat with older orchestrators
|
|
418
|
+
mockSignature: (0, validators_1.buildMockSignature)(resolveSessionForChain(signers, targetChain.id).session, config.useDevContracts, sourceChains?.length ?? 1),
|
|
419
|
+
// Per-chain map: enables accurate per-chain session validation gas simulation
|
|
420
|
+
mockSignatures: Object.fromEntries([
|
|
421
|
+
...new Set([
|
|
422
|
+
...(sourceChains ?? []).map((c) => c.id),
|
|
423
|
+
targetChain.id,
|
|
424
|
+
]),
|
|
425
|
+
].map((chainId) => [
|
|
426
|
+
String(chainId),
|
|
427
|
+
(0, validators_1.buildMockSignature)(resolveSessionForChain(signers, chainId).session, config.useDevContracts, sourceChains?.length ?? 1, chainId),
|
|
428
|
+
])),
|
|
402
429
|
}),
|
|
403
430
|
};
|
|
404
431
|
const recipient = getRecipient(recipientInput);
|
|
405
432
|
const signatureMode = signers?.type === 'experimental_session'
|
|
406
433
|
? types_1.SIG_MODE_EMISSARY_EXECUTION_ERC1271
|
|
407
434
|
: types_1.SIG_MODE_ERC1271_EMISSARY;
|
|
435
|
+
// For session signers that need enabling, pass a dummy preclaimop per source chain
|
|
436
|
+
// so the orchestrator bakes it into the bundle before computing its HMAC. The filler
|
|
437
|
+
// executes the op via verifyExecution in ENABLE mode, enabling the session on-chain
|
|
438
|
+
// without a separate UserOp. Must be sent in the routing request — not injected
|
|
439
|
+
// post-facto — because the orchestrator HMAC covers preClaimOps.
|
|
440
|
+
const preClaimExecutions = {};
|
|
441
|
+
if (signers?.type === 'experimental_session' && sourceChains) {
|
|
442
|
+
const resolvedPerChain = await Promise.all(sourceChains.map(async (chain) => ({
|
|
443
|
+
chainId: chain.id,
|
|
444
|
+
resolved: await resolveSignersForChain(config, signers, chain.id),
|
|
445
|
+
})));
|
|
446
|
+
for (const { chainId, resolved } of resolvedPerChain) {
|
|
447
|
+
if (!isResolvedSessionSignerSet(resolved))
|
|
448
|
+
continue;
|
|
449
|
+
const { enableData, verifyExecutions } = resolved;
|
|
450
|
+
if (!verifyExecutions || !enableData)
|
|
451
|
+
continue;
|
|
452
|
+
preClaimExecutions[chainId] = [
|
|
453
|
+
{
|
|
454
|
+
to: validators_1.DUMMY_PRECLAIMOP_TARGET,
|
|
455
|
+
value: 0n,
|
|
456
|
+
data: validators_1.DUMMY_PRECLAIMOP_SELECTOR,
|
|
457
|
+
},
|
|
458
|
+
];
|
|
459
|
+
}
|
|
460
|
+
}
|
|
408
461
|
const metaIntent = {
|
|
409
462
|
destinationChainId: targetChain.id,
|
|
410
463
|
tokenRequests: tokenRequests.map((tokenRequest) => ({
|
|
@@ -436,10 +489,12 @@ async function prepareTransactionAsIntent(config, sourceChains, targetChain, cal
|
|
|
436
489
|
signatureMode,
|
|
437
490
|
auxiliaryFunds,
|
|
438
491
|
},
|
|
492
|
+
...(Object.keys(preClaimExecutions).length > 0 && { preClaimExecutions }),
|
|
439
493
|
};
|
|
440
|
-
const
|
|
494
|
+
const serializedIntent = (0, utils_2.convertBigIntFields)(metaIntent);
|
|
495
|
+
const orchestrator = (0, orchestrator_1.getOrchestrator)(config._authProvider ?? (0, provider_1.createAuthProvider)(config), config.endpointUrl, config.headers);
|
|
441
496
|
const intentRoute = await orchestrator.getIntentRoute(metaIntent);
|
|
442
|
-
return intentRoute;
|
|
497
|
+
return { intentRoute, intentInput: serializedIntent };
|
|
443
498
|
}
|
|
444
499
|
async function signIntent(config, intentOp, targetChain, signers, targetExecution) {
|
|
445
500
|
const { origin, destination } = getIntentMessages(config, intentOp);
|
|
@@ -523,7 +578,7 @@ function getIntentMessages(config, intentOp) {
|
|
|
523
578
|
origin.push(typedData);
|
|
524
579
|
}
|
|
525
580
|
else if (withPermit2) {
|
|
526
|
-
const typedData = (0,
|
|
581
|
+
const typedData = (0, permit2_2.getTypedData)(element, BigInt(intentOp.nonce), BigInt(intentOp.expires));
|
|
527
582
|
origin.push(typedData);
|
|
528
583
|
}
|
|
529
584
|
else {
|
|
@@ -549,6 +604,22 @@ function getTargetExecutionMessage(config, intentOp) {
|
|
|
549
604
|
};
|
|
550
605
|
return typedData;
|
|
551
606
|
}
|
|
607
|
+
/** Computes claim policy calldata when parameters are Permit2 typed data with claim policies. */
|
|
608
|
+
function resolveClaimPolicyData(signers, parameters) {
|
|
609
|
+
if (parameters.primaryType !== 'PermitBatchWitnessTransferFrom' ||
|
|
610
|
+
!signers.session.claimPolicies?.length) {
|
|
611
|
+
return undefined;
|
|
612
|
+
}
|
|
613
|
+
const msg = parameters.message;
|
|
614
|
+
if (!msg.permitted ||
|
|
615
|
+
!msg.mandate ||
|
|
616
|
+
typeof msg.spender !== 'string' ||
|
|
617
|
+
typeof msg.nonce !== 'bigint' ||
|
|
618
|
+
typeof msg.deadline !== 'bigint') {
|
|
619
|
+
return undefined;
|
|
620
|
+
}
|
|
621
|
+
return (0, permit2_1.buildPermit2ClaimPolicyCalldata)(signers.session.claimPolicies[0], parameters.message);
|
|
622
|
+
}
|
|
552
623
|
async function signIntentTypedData(config, signers, validator, isRoot, parameters, chain, targetExecution) {
|
|
553
624
|
if ((0, core_1.supportsEip712)(validator)) {
|
|
554
625
|
const isK1Validator = validator.address.toLowerCase() ===
|
|
@@ -564,18 +635,25 @@ async function signIntentTypedData(config, signers, validator, isRoot, parameter
|
|
|
564
635
|
const hash = (0, viem_1.hashTypedData)(parameters);
|
|
565
636
|
if (isResolvedSessionSignerSet(signers) && signers.verifyExecutions) {
|
|
566
637
|
if (targetExecution) {
|
|
567
|
-
|
|
638
|
+
const targetSigners = {
|
|
568
639
|
type: 'experimental_session',
|
|
569
640
|
session: signers.session,
|
|
570
641
|
verifyExecutions: true,
|
|
571
|
-
|
|
642
|
+
enableData: signers.enableData,
|
|
643
|
+
};
|
|
644
|
+
// signWithSession (called inside getEmissarySignature) already calls packSignature
|
|
645
|
+
// internally, so no transform is needed here
|
|
646
|
+
return await (0, accounts_1.getEmissarySignature)(config, targetSigners, chain, hash);
|
|
572
647
|
}
|
|
573
|
-
const
|
|
648
|
+
const claimPolicyData = resolveClaimPolicyData(signers, parameters);
|
|
649
|
+
const sessionSignersForEip1271 = {
|
|
574
650
|
type: 'experimental_session',
|
|
575
651
|
session: signers.session,
|
|
576
652
|
verifyExecutions: false,
|
|
577
653
|
enableData: signers.enableData,
|
|
578
|
-
|
|
654
|
+
claimPolicyData,
|
|
655
|
+
};
|
|
656
|
+
const eip1271Signature = await (0, accounts_1.getEip1271Signature)(config, sessionSignersForEip1271, chain, {
|
|
579
657
|
address: validator.address,
|
|
580
658
|
isRoot,
|
|
581
659
|
}, hash);
|
|
@@ -590,6 +668,13 @@ async function signIntentTypedData(config, signers, validator, isRoot, parameter
|
|
|
590
668
|
notarizedClaimSig: eip1271Signature,
|
|
591
669
|
};
|
|
592
670
|
}
|
|
671
|
+
if (isResolvedSessionSignerSet(signers)) {
|
|
672
|
+
const claimPolicyData = resolveClaimPolicyData(signers, parameters);
|
|
673
|
+
return await (0, accounts_1.getEip1271Signature)(config, claimPolicyData !== undefined ? { ...signers, claimPolicyData } : signers, chain, {
|
|
674
|
+
address: validator.address,
|
|
675
|
+
isRoot,
|
|
676
|
+
}, hash);
|
|
677
|
+
}
|
|
593
678
|
return await (0, accounts_1.getEip1271Signature)(config, signers, chain, {
|
|
594
679
|
address: validator.address,
|
|
595
680
|
isRoot,
|
|
@@ -649,8 +734,8 @@ async function submitUserOp(config, chain, userOp, signature) {
|
|
|
649
734
|
chain: chain.id,
|
|
650
735
|
};
|
|
651
736
|
}
|
|
652
|
-
async function submitIntent(config, sourceChains, targetChain, intentOp, originSignatures, destinationSignature, targetExecutionSignature, authorizations, dryRun) {
|
|
653
|
-
return submitIntentInternal(config, sourceChains, targetChain, intentOp, originSignatures, destinationSignature, targetExecutionSignature, authorizations, dryRun);
|
|
737
|
+
async function submitIntent(config, sourceChains, targetChain, intentOp, originSignatures, destinationSignature, targetExecutionSignature, authorizations, dryRun, intentInput) {
|
|
738
|
+
return submitIntentInternal(config, sourceChains, targetChain, intentOp, originSignatures, destinationSignature, targetExecutionSignature, authorizations, dryRun, intentInput);
|
|
654
739
|
}
|
|
655
740
|
function createSignedIntentOp(intentOp, originSignatures, destinationSignature, targetExecutionSignature, authorizations) {
|
|
656
741
|
return {
|
|
@@ -670,13 +755,17 @@ function createSignedIntentOp(intentOp, originSignatures, destinationSignature,
|
|
|
670
755
|
: undefined,
|
|
671
756
|
};
|
|
672
757
|
}
|
|
673
|
-
async function submitIntentInternal(config, sourceChains, targetChain, intentOp, originSignatures, destinationSignature, targetExecutionSignature, authorizations, dryRun) {
|
|
758
|
+
async function submitIntentInternal(config, sourceChains, targetChain, intentOp, originSignatures, destinationSignature, targetExecutionSignature, authorizations, dryRun, intentInput) {
|
|
674
759
|
const signedIntentOp = createSignedIntentOp(intentOp, originSignatures, destinationSignature, targetExecutionSignature, authorizations);
|
|
675
|
-
const
|
|
676
|
-
const
|
|
760
|
+
const isSponsored = !!intentInput?.options?.sponsorSettings;
|
|
761
|
+
const orchestrator = (0, orchestrator_1.getOrchestrator)(config._authProvider ?? (0, provider_1.createAuthProvider)(config), config.endpointUrl, config.headers);
|
|
762
|
+
const intentResults = await orchestrator.submitIntent(signedIntentOp, dryRun, intentInput ? { intentInput, isSponsored } : undefined);
|
|
763
|
+
// Some settlement paths (e.g. SAME_CHAIN) may not return a result.id — fall
|
|
764
|
+
// back to the nonce which the orchestrator also accepts as an intent identifier.
|
|
765
|
+
const intentId = intentResults.result.id ?? intentOp.nonce;
|
|
677
766
|
return {
|
|
678
767
|
type: 'intent',
|
|
679
|
-
id: BigInt(
|
|
768
|
+
id: BigInt(intentId),
|
|
680
769
|
sourceChains: sourceChains?.map((chain) => chain.id),
|
|
681
770
|
targetChain: targetChain.id,
|
|
682
771
|
};
|
package/dist/src/index.d.ts
CHANGED
|
@@ -8,7 +8,7 @@ import { type IntentRoute, type PreparedTransactionData, type PreparedUserOperat
|
|
|
8
8
|
import { MULTI_FACTOR_VALIDATOR_ADDRESS, OWNABLE_VALIDATOR_ADDRESS, SMART_SESSION_EMISSARY_ADDRESS, WEBAUTHN_VALIDATOR_ADDRESS } from './modules';
|
|
9
9
|
import { type SessionDetails } from './modules/validators/smart-sessions';
|
|
10
10
|
import { type ApprovalRequired, type AuxiliaryFunds, getAllSupportedChainsAndTokens, getSupportedTokens, getTokenAddress, getTokenDecimals, type IntentInput, type IntentOp, type IntentOpStatus, type Portfolio, type SettlementLayer, type SignedIntentOp, type SplitIntentsInput, type SplitIntentsResult, type TokenRequirements, type WrapRequired } from './orchestrator';
|
|
11
|
-
import type { AccountProviderConfig, AccountType, BundlerConfig, Call, CallInput, ChainSessionConfig, MultiFactorValidatorConfig, OwnableValidatorConfig, OwnerSet, PaymasterConfig, Policy, ProviderConfig, Recovery, RhinestoneAccountConfig, RhinestoneConfig, RhinestoneSDKConfig, Session, SignerSet, TokenRequest, TokenSymbol, Transaction, UniversalActionPolicyParamCondition, UserOperationTransaction, WebauthnValidatorConfig } from './types';
|
|
11
|
+
import type { AccountProviderConfig, AccountType, BundlerConfig, Call, CallInput, ChainSessionConfig, MultiFactorValidatorConfig, OwnableValidatorConfig, OwnerSet, PaymasterConfig, Permit2ClaimPolicy, Policy, ProviderConfig, Recovery, RhinestoneAccountConfig, RhinestoneConfig, RhinestoneSDKConfig, Session, SignerSet, TokenRequest, TokenSymbol, Transaction, UniversalActionPolicyParamCondition, UserOperationTransaction, WebauthnValidatorConfig } from './types';
|
|
12
12
|
interface RhinestoneAccount {
|
|
13
13
|
config: RhinestoneAccountConfig;
|
|
14
14
|
deploy: (chain: Chain, params?: {
|
|
@@ -60,7 +60,7 @@ interface RhinestoneAccount {
|
|
|
60
60
|
*/
|
|
61
61
|
declare function createRhinestoneAccount(config: RhinestoneConfig): Promise<RhinestoneAccount>;
|
|
62
62
|
declare class RhinestoneSDK {
|
|
63
|
-
private
|
|
63
|
+
private authProvider;
|
|
64
64
|
private endpointUrl?;
|
|
65
65
|
private provider?;
|
|
66
66
|
private bundler?;
|
|
@@ -75,5 +75,5 @@ declare class RhinestoneSDK {
|
|
|
75
75
|
splitIntents(input: SplitIntentsInput): Promise<SplitIntentsResult>;
|
|
76
76
|
}
|
|
77
77
|
export { RhinestoneSDK, createRhinestoneAccount, deployAccountsForOwners, walletClientToAccount, wrapParaAccount, OWNABLE_VALIDATOR_ADDRESS, WEBAUTHN_VALIDATOR_ADDRESS, MULTI_FACTOR_VALIDATOR_ADDRESS, SMART_SESSION_EMISSARY_ADDRESS, getSupportedTokens, getTokenAddress, getTokenDecimals, getAllSupportedChainsAndTokens, checkERC20AllowanceDirect, getPermit2Address, signPermit2Batch, signPermit2Sequential, };
|
|
78
|
-
export type { RhinestoneAccount, AccountType, RhinestoneAccountConfig, AccountProviderConfig, ProviderConfig, BundlerConfig, PaymasterConfig, Transaction, TokenSymbol, CallInput, Call, TokenRequest, OwnerSet, OwnableValidatorConfig, WebauthnValidatorConfig, MultiFactorValidatorConfig, SignerSet, ChainSessionConfig, Session, Recovery, Policy, UniversalActionPolicyParamCondition, PreparedTransactionData, SignedTransactionData, TransactionResult, PreparedUserOperationData, SignedUserOperationData, UserOperationResult, AuxiliaryFunds, IntentInput, IntentOp, IntentOpStatus, IntentRoute, SettlementLayer, SignedIntentOp, SplitIntentsInput, SplitIntentsResult, Portfolio, TokenRequirements, WrapRequired, ApprovalRequired, MultiChainPermit2Config, MultiChainPermit2Result, BatchPermit2Result, };
|
|
78
|
+
export type { RhinestoneAccount, AccountType, RhinestoneAccountConfig, AccountProviderConfig, ProviderConfig, BundlerConfig, PaymasterConfig, Transaction, TokenSymbol, CallInput, Call, TokenRequest, OwnerSet, OwnableValidatorConfig, WebauthnValidatorConfig, MultiFactorValidatorConfig, SignerSet, ChainSessionConfig, Session, Recovery, Policy, Permit2ClaimPolicy, UniversalActionPolicyParamCondition, PreparedTransactionData, SignedTransactionData, TransactionResult, PreparedUserOperationData, SignedUserOperationData, UserOperationResult, AuxiliaryFunds, IntentInput, IntentOp, IntentOpStatus, IntentRoute, SettlementLayer, SignedIntentOp, SplitIntentsInput, SplitIntentsResult, Portfolio, TokenRequirements, WrapRequired, ApprovalRequired, MultiChainPermit2Config, MultiChainPermit2Result, BatchPermit2Result, };
|
|
79
79
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/src/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,OAAO,EACP,KAAK,EACL,uBAAuB,EACvB,GAAG,EACH,eAAe,EACf,uBAAuB,EACvB,SAAS,EACT,mBAAmB,EACpB,MAAM,MAAM,CAAA;AACb,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,0BAA0B,CAAA;AAapE,OAAO,EAAE,qBAAqB,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAA;AAChF,OAAO,EAAE,uBAAuB,EAAE,MAAM,sBAAsB,CAAA;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,OAAO,EACP,KAAK,EACL,uBAAuB,EACvB,GAAG,EACH,eAAe,EACf,uBAAuB,EACvB,SAAS,EACT,mBAAmB,EACpB,MAAM,MAAM,CAAA;AACb,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,0BAA0B,CAAA;AAapE,OAAO,EAAE,qBAAqB,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAA;AAChF,OAAO,EAAE,uBAAuB,EAAE,MAAM,sBAAsB,CAAA;AAE9D,OAAO,EAML,KAAK,iBAAiB,EACtB,KAAK,iBAAiB,EACtB,K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BAAgB,EAChB,qBAAqB,GACtB,CAAA;AACD,YAAY,EACV,iBAAiB,EACjB,WAAW,EACX,uBAAuB,EACvB,qBAAqB,EACrB,cAAc,EACd,aAAa,EACb,eAAe,EACf,WAAW,EACX,WAAW,EACX,SAAS,EACT,IAAI,EACJ,YAAY,EACZ,QAAQ,EACR,sBAAsB,EACtB,uBAAuB,EACvB,0BAA0B,EAC1B,SAAS,EACT,kBAAkB,EAClB,OAAO,EACP,QAAQ,EACR,MAAM,EACN,kBAAkB,EAClB,mCAAmC,EACnC,uBAAuB,EACvB,qBAAqB,EACrB,iBAAiB,EACjB,yBAAyB,EACzB,uBAAuB,EACvB,mBAAmB,EACnB,cAAc,EACd,WAAW,EACX,QAAQ,EACR,cAAc,EACd,WAAW,EACX,eAAe,EACf,cAAc,EACd,iBAAiB,EACjB,kBAAkB,EAClB,SAAS,EACT,iBAAiB,EACjB,YAAY,EACZ,gBAAgB,EAEhB,uBAAuB,EACvB,uBAAuB,EACvB,kBAAkB,GACnB,CAAA"}
|
package/dist/src/index.js
CHANGED
|
@@ -8,6 +8,7 @@ Object.defineProperty(exports, "walletClientToAccount", { enumerable: true, get:
|
|
|
8
8
|
Object.defineProperty(exports, "wrapParaAccount", { enumerable: true, get: function () { return walletClient_1.wrapParaAccount; } });
|
|
9
9
|
const deployment_1 = require("./actions/deployment");
|
|
10
10
|
Object.defineProperty(exports, "deployAccountsForOwners", { enumerable: true, get: function () { return deployment_1.deployAccountsForOwners; } });
|
|
11
|
+
const provider_1 = require("./auth/provider");
|
|
11
12
|
const execution_1 = require("./execution");
|
|
12
13
|
const permit2_1 = require("./execution/permit2");
|
|
13
14
|
Object.defineProperty(exports, "checkERC20AllowanceDirect", { enumerable: true, get: function () { return permit2_1.checkERC20AllowanceDirect; } });
|
|
@@ -293,7 +294,7 @@ async function createRhinestoneAccount(config) {
|
|
|
293
294
|
};
|
|
294
295
|
}
|
|
295
296
|
class RhinestoneSDK {
|
|
296
|
-
|
|
297
|
+
authProvider;
|
|
297
298
|
endpointUrl;
|
|
298
299
|
provider;
|
|
299
300
|
bundler;
|
|
@@ -301,7 +302,7 @@ class RhinestoneSDK {
|
|
|
301
302
|
useDevContracts;
|
|
302
303
|
headers;
|
|
303
304
|
constructor(options) {
|
|
304
|
-
this.
|
|
305
|
+
this.authProvider = (0, provider_1.createAuthProvider)(options);
|
|
305
306
|
this.endpointUrl = options.endpointUrl;
|
|
306
307
|
this.provider = options.provider;
|
|
307
308
|
this.bundler = options.bundler;
|
|
@@ -312,7 +313,7 @@ class RhinestoneSDK {
|
|
|
312
313
|
createAccount(config) {
|
|
313
314
|
const rhinestoneConfig = {
|
|
314
315
|
...config,
|
|
315
|
-
|
|
316
|
+
_authProvider: this.authProvider,
|
|
316
317
|
endpointUrl: this.endpointUrl,
|
|
317
318
|
provider: this.provider,
|
|
318
319
|
bundler: this.bundler,
|
|
@@ -323,10 +324,10 @@ class RhinestoneSDK {
|
|
|
323
324
|
return createRhinestoneAccount(rhinestoneConfig);
|
|
324
325
|
}
|
|
325
326
|
getIntentStatus(intentId) {
|
|
326
|
-
return (0, execution_1.getIntentStatus)(this.
|
|
327
|
+
return (0, execution_1.getIntentStatus)(this.authProvider, this.endpointUrl, intentId, this.headers);
|
|
327
328
|
}
|
|
328
329
|
splitIntents(input) {
|
|
329
|
-
return (0, execution_1.splitIntents)(this.
|
|
330
|
+
return (0, execution_1.splitIntents)(this.authProvider, this.endpointUrl, input, this.headers);
|
|
330
331
|
}
|
|
331
332
|
}
|
|
332
333
|
exports.RhinestoneSDK = RhinestoneSDK;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Compute a deterministic hex-encoded SHA-256 digest of an intent input object.
|
|
3
|
+
*
|
|
4
|
+
* 1. JCS-canonicalise the intent input (RFC 8785)
|
|
5
|
+
* 2. SHA-256 hash the UTF-8 bytes
|
|
6
|
+
* 3. Return lowercase hex string
|
|
7
|
+
*
|
|
8
|
+
* Uses the Web Crypto API (available in Node.js ≥ 15 and all modern browsers).
|
|
9
|
+
*/
|
|
10
|
+
export declare function computeIntentInputDigest(intentInput: unknown): Promise<string>;
|
|
11
|
+
//# sourceMappingURL=digest.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"digest.d.ts","sourceRoot":"","sources":["../../../jwt-server/digest.ts"],"names":[],"mappings":"AAEA;;;;;;;;GAQG;AACH,wBAAsB,wBAAwB,CAC5C,WAAW,EAAE,OAAO,GACnB,OAAO,CAAC,MAAM,CAAC,CAQjB"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.computeIntentInputDigest = computeIntentInputDigest;
|
|
4
|
+
const jcs_1 = require("./jcs");
|
|
5
|
+
/**
|
|
6
|
+
* Compute a deterministic hex-encoded SHA-256 digest of an intent input object.
|
|
7
|
+
*
|
|
8
|
+
* 1. JCS-canonicalise the intent input (RFC 8785)
|
|
9
|
+
* 2. SHA-256 hash the UTF-8 bytes
|
|
10
|
+
* 3. Return lowercase hex string
|
|
11
|
+
*
|
|
12
|
+
* Uses the Web Crypto API (available in Node.js ≥ 15 and all modern browsers).
|
|
13
|
+
*/
|
|
14
|
+
async function computeIntentInputDigest(intentInput) {
|
|
15
|
+
const canonical = (0, jcs_1.jcsCanonicalise)(intentInput);
|
|
16
|
+
const encoded = new TextEncoder().encode(canonical);
|
|
17
|
+
const hashBuffer = await crypto.subtle.digest('SHA-256', encoded);
|
|
18
|
+
const hashArray = new Uint8Array(hashBuffer);
|
|
19
|
+
return Array.from(hashArray)
|
|
20
|
+
.map((b) => b.toString(16).padStart(2, '0'))
|
|
21
|
+
.join('');
|
|
22
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { type JwtHandlerConfig } from './handlers';
|
|
2
|
+
interface ExpressRequest {
|
|
3
|
+
body?: unknown;
|
|
4
|
+
}
|
|
5
|
+
interface ExpressResponse {
|
|
6
|
+
status(code: number): ExpressResponse;
|
|
7
|
+
json(body: unknown): void;
|
|
8
|
+
}
|
|
9
|
+
type ExpressHandler = (req: ExpressRequest, res: ExpressResponse) => void;
|
|
10
|
+
interface ExpressRouter {
|
|
11
|
+
get(path: string, handler: ExpressHandler): ExpressRouter;
|
|
12
|
+
post(path: string, handler: ExpressHandler): ExpressRouter;
|
|
13
|
+
}
|
|
14
|
+
export declare function createExpressRouter(config: JwtHandlerConfig): ExpressRouter;
|
|
15
|
+
export {};
|
|
16
|
+
//# sourceMappingURL=express.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"express.d.ts","sourceRoot":"","sources":["../../../jwt-server/express.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,KAAK,gBAAgB,EACtB,MAAM,YAAY,CAAA;AAEnB,UAAU,cAAc;IACtB,IAAI,CAAC,EAAE,OAAO,CAAA;CACf;AAED,UAAU,eAAe;IACvB,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,eAAe,CAAA;IACrC,IAAI,CAAC,IAAI,EAAE,OAAO,GAAG,IAAI,CAAA;CAC1B;AAED,KAAK,cAAc,GAAG,CAAC,GAAG,EAAE,cAAc,EAAE,GAAG,EAAE,eAAe,KAAK,IAAI,CAAA;AAEzE,UAAU,aAAa;IACrB,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,cAAc,GAAG,aAAa,CAAA;IACzD,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,cAAc,GAAG,aAAa,CAAA;CAC3D;AAED,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,gBAAgB,GAAG,aAAa,CAyB3E"}
|
|
@@ -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"}
|