@rhinestone/sdk 2.0.0-beta.2 → 2.0.0-beta.20
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/dist/src/accounts/index.d.ts +5 -5
- package/dist/src/accounts/index.d.ts.map +1 -1
- package/dist/src/accounts/index.js +46 -2
- package/dist/src/actions/ecdsa.js +2 -2
- package/dist/src/actions/index.js +2 -2
- package/dist/src/actions/mfa.js +2 -2
- package/dist/src/actions/passkeys.js +2 -2
- package/dist/src/actions/smart-sessions.d.ts +11 -3
- package/dist/src/actions/smart-sessions.d.ts.map +1 -1
- package/dist/src/actions/smart-sessions.js +14 -9
- package/dist/src/errors/index.d.ts +3 -3
- package/dist/src/errors/index.d.ts.map +1 -1
- package/dist/src/errors/index.js +4 -4
- package/dist/src/execution/error.d.ts +8 -7
- package/dist/src/execution/error.d.ts.map +1 -1
- package/dist/src/execution/error.js +7 -5
- package/dist/src/execution/index.d.ts +16 -17
- package/dist/src/execution/index.d.ts.map +1 -1
- package/dist/src/execution/index.js +18 -34
- package/dist/src/execution/utils.d.ts +15 -11
- package/dist/src/execution/utils.d.ts.map +1 -1
- package/dist/src/execution/utils.js +259 -56
- package/dist/src/index.d.ts +6 -7
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +3 -0
- package/dist/src/modules/validators/permissions.d.ts.map +1 -1
- package/dist/src/modules/validators/permissions.js +161 -17
- package/dist/src/modules/validators/smart-sessions.d.ts +24 -8
- package/dist/src/modules/validators/smart-sessions.d.ts.map +1 -1
- package/dist/src/modules/validators/smart-sessions.js +227 -83
- package/dist/src/orchestrator/caip2.d.ts +9 -3
- package/dist/src/orchestrator/caip2.d.ts.map +1 -1
- package/dist/src/orchestrator/caip2.js +40 -5
- package/dist/src/orchestrator/client.d.ts +2 -1
- package/dist/src/orchestrator/client.d.ts.map +1 -1
- package/dist/src/orchestrator/client.js +56 -30
- package/dist/src/orchestrator/consts.d.ts +1 -1
- package/dist/src/orchestrator/consts.d.ts.map +1 -1
- package/dist/src/orchestrator/consts.js +1 -1
- package/dist/src/orchestrator/destinations.d.ts +23 -0
- package/dist/src/orchestrator/destinations.d.ts.map +1 -0
- package/dist/src/orchestrator/destinations.js +36 -0
- package/dist/src/orchestrator/error.d.ts +22 -3
- package/dist/src/orchestrator/error.d.ts.map +1 -1
- package/dist/src/orchestrator/error.js +32 -2
- package/dist/src/orchestrator/index.d.ts +6 -5
- package/dist/src/orchestrator/index.d.ts.map +1 -1
- package/dist/src/orchestrator/index.js +4 -3
- 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 +10 -0
- package/dist/src/orchestrator/types.d.ts +103 -35
- package/dist/src/orchestrator/types.d.ts.map +1 -1
- package/dist/src/orchestrator/types.js +1 -5
- package/dist/src/types.d.ts +148 -15
- package/dist/src/types.d.ts.map +1 -1
- package/package.json +2 -2
|
@@ -68,12 +68,13 @@ const SMART_SESSIONS_FALLBACK_TARGET_SELECTOR_FLAG_PERMITTED_TO_CALL_SMARTSESSIO
|
|
|
68
68
|
// intentionally uncommon.
|
|
69
69
|
const DUMMY_PRECLAIMOP_TARGET = '0x0000000000000000000000000000000000000420';
|
|
70
70
|
const DUMMY_PRECLAIMOP_SELECTOR = '0x69123456';
|
|
71
|
-
const SPENDING_LIMITS_POLICY_ADDRESS = '
|
|
72
|
-
const TIME_FRAME_POLICY_ADDRESS = '
|
|
73
|
-
const SUDO_POLICY_ADDRESS = '
|
|
74
|
-
const UNIVERSAL_ACTION_POLICY_ADDRESS = '
|
|
75
|
-
const
|
|
76
|
-
const
|
|
71
|
+
const SPENDING_LIMITS_POLICY_ADDRESS = '0x000000000033212E272655D8a22402Db819477A6';
|
|
72
|
+
const TIME_FRAME_POLICY_ADDRESS = '0x0000000000D30f611fA3bf652ac6879428586930';
|
|
73
|
+
const SUDO_POLICY_ADDRESS = '0x0000000000FEEc8D74e3143fBaBbca515358d869';
|
|
74
|
+
const UNIVERSAL_ACTION_POLICY_ADDRESS = '0x0000000000714Cf48FcF88A0bFBa70d313415032';
|
|
75
|
+
const ARG_POLICY_ADDRESS = '0x0000000000167edE64D8751daACDdC0312565a73';
|
|
76
|
+
const USAGE_LIMIT_POLICY_ADDRESS = '0x00000000001d4479FA2A947026204d0283ceDe4B';
|
|
77
|
+
const VALUE_LIMIT_POLICY_ADDRESS = '0x000000000021dC45451291BCDfc9f0B46d6f0278';
|
|
77
78
|
const INTENT_EXECUTION_POLICY_ADDRESS = '0xe9eA54d063975cDee9e06b7636d5563d95a7A23C';
|
|
78
79
|
const INTENT_EXECUTION_POLICY_ADDRESS_DEV = '0xa09b47de6e510cbdc18b97e9239bedcb44fb4901';
|
|
79
80
|
const ACTION_CONDITION_EQUAL = 0;
|
|
@@ -83,6 +84,44 @@ const ACTION_CONDITION_GREATER_THAN_OR_EQUAL = 3;
|
|
|
83
84
|
const ACTION_CONDITION_LESS_THAN_OR_EQUAL = 4;
|
|
84
85
|
const ACTION_CONDITION_NOT_EQUAL = 5;
|
|
85
86
|
const ACTION_CONDITION_IN_RANGE = 6;
|
|
87
|
+
// ArgPolicy expression-tree node packing — must match ArgPolicyTreeLib.sol:
|
|
88
|
+
// bits 0..1 : node type (0=rule, 1=NOT, 2=AND, 3=OR)
|
|
89
|
+
// bits 2..9 : rule index (rule nodes only)
|
|
90
|
+
// bits 10..17 : left/only child index
|
|
91
|
+
// bits 18..25 : right child index (AND/OR only)
|
|
92
|
+
const ARG_NODE_TYPE_RULE = 0n;
|
|
93
|
+
const ARG_NODE_TYPE_NOT = 1n;
|
|
94
|
+
const ARG_NODE_TYPE_AND = 2n;
|
|
95
|
+
const ARG_NODE_TYPE_OR = 3n;
|
|
96
|
+
const ARG_RULE_INDEX_SHIFT = 2n;
|
|
97
|
+
const ARG_LEFT_CHILD_SHIFT = 10n;
|
|
98
|
+
const ARG_RIGHT_CHILD_SHIFT = 18n;
|
|
99
|
+
// On-chain caps from ArgPolicyTreeLib.sol; fail early instead of letting
|
|
100
|
+
// the deployment revert with `TooManyRules` / `TooManyNodes`.
|
|
101
|
+
const ARG_MAX_RULES = 128;
|
|
102
|
+
const ARG_MAX_NODES = 256;
|
|
103
|
+
const DEFAULT_POLICY_ADDRESSES = {
|
|
104
|
+
sudo: SUDO_POLICY_ADDRESS,
|
|
105
|
+
universalAction: UNIVERSAL_ACTION_POLICY_ADDRESS,
|
|
106
|
+
argPolicy: ARG_POLICY_ADDRESS,
|
|
107
|
+
spendingLimits: SPENDING_LIMITS_POLICY_ADDRESS,
|
|
108
|
+
timeFrame: TIME_FRAME_POLICY_ADDRESS,
|
|
109
|
+
usageLimit: USAGE_LIMIT_POLICY_ADDRESS,
|
|
110
|
+
valueLimit: VALUE_LIMIT_POLICY_ADDRESS,
|
|
111
|
+
};
|
|
112
|
+
function resolvePolicyAddresses(overrides) {
|
|
113
|
+
if (!overrides)
|
|
114
|
+
return DEFAULT_POLICY_ADDRESSES;
|
|
115
|
+
return {
|
|
116
|
+
sudo: overrides.sudo ?? DEFAULT_POLICY_ADDRESSES.sudo,
|
|
117
|
+
universalAction: overrides.universalAction ?? DEFAULT_POLICY_ADDRESSES.universalAction,
|
|
118
|
+
argPolicy: overrides.argPolicy ?? DEFAULT_POLICY_ADDRESSES.argPolicy,
|
|
119
|
+
spendingLimits: overrides.spendingLimits ?? DEFAULT_POLICY_ADDRESSES.spendingLimits,
|
|
120
|
+
timeFrame: overrides.timeFrame ?? DEFAULT_POLICY_ADDRESSES.timeFrame,
|
|
121
|
+
usageLimit: overrides.usageLimit ?? DEFAULT_POLICY_ADDRESSES.usageLimit,
|
|
122
|
+
valueLimit: overrides.valueLimit ?? DEFAULT_POLICY_ADDRESSES.valueLimit,
|
|
123
|
+
};
|
|
124
|
+
}
|
|
86
125
|
function packSignature(signers, validatorSignature) {
|
|
87
126
|
const session = signers.session;
|
|
88
127
|
const permissionId = getPermissionId(session);
|
|
@@ -390,7 +429,8 @@ async function getEnableSessionCall(account, session, enableSessionSignature, ha
|
|
|
390
429
|
};
|
|
391
430
|
}
|
|
392
431
|
function toSession(definition, options = {}) {
|
|
393
|
-
const
|
|
432
|
+
const addresses = resolvePolicyAddresses(definition.policyAddresses);
|
|
433
|
+
const sessionData = resolveSessionData(definition, options.useDevContracts, addresses);
|
|
394
434
|
return {
|
|
395
435
|
chain: definition.chain,
|
|
396
436
|
owners: definition.owners,
|
|
@@ -429,7 +469,7 @@ function resolvePermit2ClaimPolicy(policy) {
|
|
|
429
469
|
})),
|
|
430
470
|
};
|
|
431
471
|
}
|
|
432
|
-
function resolveSessionData(session, useDevContracts) {
|
|
472
|
+
function resolveSessionData(session, useDevContracts, addresses = DEFAULT_POLICY_ADDRESSES) {
|
|
433
473
|
const validator = getValidator(session.owners);
|
|
434
474
|
const allowedContent = [
|
|
435
475
|
{
|
|
@@ -441,7 +481,7 @@ function resolveSessionData(session, useDevContracts) {
|
|
|
441
481
|
allowedERC7739Content: allowedContent,
|
|
442
482
|
erc1271Policies: [
|
|
443
483
|
{
|
|
444
|
-
policy:
|
|
484
|
+
policy: addresses.sudo,
|
|
445
485
|
initData: '0x',
|
|
446
486
|
},
|
|
447
487
|
],
|
|
@@ -451,7 +491,7 @@ function resolveSessionData(session, useDevContracts) {
|
|
|
451
491
|
actionTarget: SMART_SESSIONS_FALLBACK_TARGET_FLAG,
|
|
452
492
|
actionPolicies: [
|
|
453
493
|
{
|
|
454
|
-
policy:
|
|
494
|
+
policy: addresses.sudo,
|
|
455
495
|
initData: '0x',
|
|
456
496
|
},
|
|
457
497
|
],
|
|
@@ -491,9 +531,9 @@ function resolveSessionData(session, useDevContracts) {
|
|
|
491
531
|
actionTarget: 'target' in action
|
|
492
532
|
? action.target
|
|
493
533
|
: SMART_SESSIONS_FALLBACK_TARGET_FLAG,
|
|
494
|
-
actionPolicies: action.policies?.map((policy) => getPolicyData(policy, useDevContracts)) ?? [
|
|
534
|
+
actionPolicies: action.policies?.map((policy) => getPolicyData(policy, useDevContracts, addresses)) ?? [
|
|
495
535
|
{
|
|
496
|
-
policy:
|
|
536
|
+
policy: addresses.sudo,
|
|
497
537
|
initData: '0x',
|
|
498
538
|
},
|
|
499
539
|
],
|
|
@@ -547,11 +587,88 @@ function getPermissionIdFromData(sessionData) {
|
|
|
547
587
|
sessionData.salt,
|
|
548
588
|
]));
|
|
549
589
|
}
|
|
550
|
-
function
|
|
590
|
+
function getActionConditionId(condition) {
|
|
591
|
+
switch (condition) {
|
|
592
|
+
case 'equal':
|
|
593
|
+
return ACTION_CONDITION_EQUAL;
|
|
594
|
+
case 'greaterThan':
|
|
595
|
+
return ACTION_CONDITION_GREATER_THAN;
|
|
596
|
+
case 'lessThan':
|
|
597
|
+
return ACTION_CONDITION_LESS_THAN;
|
|
598
|
+
case 'greaterThanOrEqual':
|
|
599
|
+
return ACTION_CONDITION_GREATER_THAN_OR_EQUAL;
|
|
600
|
+
case 'lessThanOrEqual':
|
|
601
|
+
return ACTION_CONDITION_LESS_THAN_OR_EQUAL;
|
|
602
|
+
case 'notEqual':
|
|
603
|
+
return ACTION_CONDITION_NOT_EQUAL;
|
|
604
|
+
case 'inRange':
|
|
605
|
+
return ACTION_CONDITION_IN_RANGE;
|
|
606
|
+
}
|
|
607
|
+
}
|
|
608
|
+
function encodeActionParamRule(rule) {
|
|
609
|
+
const ref = isHex(rule.referenceValue)
|
|
610
|
+
? padHex(rule.referenceValue)
|
|
611
|
+
: toHex(rule.referenceValue, { size: 32 });
|
|
612
|
+
return {
|
|
613
|
+
condition: getActionConditionId(rule.condition),
|
|
614
|
+
offset: rule.calldataOffset,
|
|
615
|
+
isLimited: rule.usageLimit !== undefined,
|
|
616
|
+
ref,
|
|
617
|
+
usage: {
|
|
618
|
+
limit: rule.usageLimit ?? 0n,
|
|
619
|
+
used: 0n,
|
|
620
|
+
},
|
|
621
|
+
};
|
|
622
|
+
}
|
|
623
|
+
// Compile an ArgPolicyExpression AST into the on-chain wire format
|
|
624
|
+
// (flat rules[] + bit-packed nodes[] + rootNodeIndex). Post-order walk:
|
|
625
|
+
// children get appended before their parent so a parent's child indices
|
|
626
|
+
// always reference earlier slots.
|
|
627
|
+
function compileArgPolicyExpression(expr) {
|
|
628
|
+
const rules = [];
|
|
629
|
+
const nodes = [];
|
|
630
|
+
function walk(e) {
|
|
631
|
+
switch (e.type) {
|
|
632
|
+
case 'rule': {
|
|
633
|
+
const ruleIdx = rules.length;
|
|
634
|
+
rules.push(encodeActionParamRule(e.rule));
|
|
635
|
+
const nodeIdx = nodes.length;
|
|
636
|
+
nodes.push(ARG_NODE_TYPE_RULE | (BigInt(ruleIdx) << ARG_RULE_INDEX_SHIFT));
|
|
637
|
+
return nodeIdx;
|
|
638
|
+
}
|
|
639
|
+
case 'not': {
|
|
640
|
+
const childIdx = walk(e.child);
|
|
641
|
+
const nodeIdx = nodes.length;
|
|
642
|
+
nodes.push(ARG_NODE_TYPE_NOT | (BigInt(childIdx) << ARG_LEFT_CHILD_SHIFT));
|
|
643
|
+
return nodeIdx;
|
|
644
|
+
}
|
|
645
|
+
case 'and':
|
|
646
|
+
case 'or': {
|
|
647
|
+
const leftIdx = walk(e.left);
|
|
648
|
+
const rightIdx = walk(e.right);
|
|
649
|
+
const nodeIdx = nodes.length;
|
|
650
|
+
const nodeType = e.type === 'and' ? ARG_NODE_TYPE_AND : ARG_NODE_TYPE_OR;
|
|
651
|
+
nodes.push(nodeType |
|
|
652
|
+
(BigInt(leftIdx) << ARG_LEFT_CHILD_SHIFT) |
|
|
653
|
+
(BigInt(rightIdx) << ARG_RIGHT_CHILD_SHIFT));
|
|
654
|
+
return nodeIdx;
|
|
655
|
+
}
|
|
656
|
+
}
|
|
657
|
+
}
|
|
658
|
+
const rootNodeIndex = walk(expr);
|
|
659
|
+
if (rules.length > ARG_MAX_RULES) {
|
|
660
|
+
throw new Error(`ArgPolicy expression has ${rules.length} rules, max is ${ARG_MAX_RULES}`);
|
|
661
|
+
}
|
|
662
|
+
if (nodes.length > ARG_MAX_NODES) {
|
|
663
|
+
throw new Error(`ArgPolicy expression has ${nodes.length} nodes, max is ${ARG_MAX_NODES}`);
|
|
664
|
+
}
|
|
665
|
+
return { rules, packedNodes: nodes, rootNodeIndex };
|
|
666
|
+
}
|
|
667
|
+
function getPolicyData(policy, useDevContracts, addresses = DEFAULT_POLICY_ADDRESSES) {
|
|
551
668
|
switch (policy.type) {
|
|
552
669
|
case 'sudo':
|
|
553
670
|
return {
|
|
554
|
-
policy:
|
|
671
|
+
policy: addresses.sudo,
|
|
555
672
|
initData: '0x',
|
|
556
673
|
};
|
|
557
674
|
case 'intent-execution':
|
|
@@ -562,24 +679,6 @@ function getPolicyData(policy, useDevContracts) {
|
|
|
562
679
|
initData: '0x',
|
|
563
680
|
};
|
|
564
681
|
case 'universal-action': {
|
|
565
|
-
function getCondition(condition) {
|
|
566
|
-
switch (condition) {
|
|
567
|
-
case 'equal':
|
|
568
|
-
return ACTION_CONDITION_EQUAL;
|
|
569
|
-
case 'greaterThan':
|
|
570
|
-
return ACTION_CONDITION_GREATER_THAN;
|
|
571
|
-
case 'lessThan':
|
|
572
|
-
return ACTION_CONDITION_LESS_THAN;
|
|
573
|
-
case 'greaterThanOrEqual':
|
|
574
|
-
return ACTION_CONDITION_GREATER_THAN_OR_EQUAL;
|
|
575
|
-
case 'lessThanOrEqual':
|
|
576
|
-
return ACTION_CONDITION_LESS_THAN_OR_EQUAL;
|
|
577
|
-
case 'notEqual':
|
|
578
|
-
return ACTION_CONDITION_NOT_EQUAL;
|
|
579
|
-
case 'inRange':
|
|
580
|
-
return ACTION_CONDITION_IN_RANGE;
|
|
581
|
-
}
|
|
582
|
-
}
|
|
583
682
|
const MAX_RULES = 16;
|
|
584
683
|
const rules = createFixedArray(MAX_RULES, () => ({
|
|
585
684
|
condition: ACTION_CONDITION_EQUAL,
|
|
@@ -589,23 +688,10 @@ function getPolicyData(policy, useDevContracts) {
|
|
|
589
688
|
usage: { limit: 0n, used: 0n },
|
|
590
689
|
}));
|
|
591
690
|
for (let i = 0; i < policy.rules.length; i++) {
|
|
592
|
-
|
|
593
|
-
const ref = isHex(rule.referenceValue)
|
|
594
|
-
? padHex(rule.referenceValue)
|
|
595
|
-
: toHex(rule.referenceValue, { size: 32 });
|
|
596
|
-
rules[i] = {
|
|
597
|
-
condition: getCondition(rule.condition),
|
|
598
|
-
offset: rule.calldataOffset,
|
|
599
|
-
isLimited: rule.usageLimit !== undefined,
|
|
600
|
-
ref,
|
|
601
|
-
usage: {
|
|
602
|
-
limit: rule.usageLimit ? rule.usageLimit : 0n,
|
|
603
|
-
used: 0n,
|
|
604
|
-
},
|
|
605
|
-
};
|
|
691
|
+
rules[i] = encodeActionParamRule(policy.rules[i]);
|
|
606
692
|
}
|
|
607
693
|
return {
|
|
608
|
-
policy:
|
|
694
|
+
policy: addresses.universalAction,
|
|
609
695
|
initData: encodeAbiParameters([
|
|
610
696
|
{
|
|
611
697
|
components: [
|
|
@@ -674,17 +760,69 @@ function getPolicyData(policy, useDevContracts) {
|
|
|
674
760
|
]),
|
|
675
761
|
};
|
|
676
762
|
}
|
|
763
|
+
case 'arg-policy': {
|
|
764
|
+
const { rules, packedNodes, rootNodeIndex } = compileArgPolicyExpression(policy.expression);
|
|
765
|
+
return {
|
|
766
|
+
policy: addresses.argPolicy,
|
|
767
|
+
initData: encodeAbiParameters([
|
|
768
|
+
{
|
|
769
|
+
components: [
|
|
770
|
+
{ name: 'valueLimitPerUse', type: 'uint256' },
|
|
771
|
+
{
|
|
772
|
+
components: [
|
|
773
|
+
{ name: 'rootNodeIndex', type: 'uint8' },
|
|
774
|
+
{
|
|
775
|
+
components: [
|
|
776
|
+
{ name: 'condition', type: 'uint8' },
|
|
777
|
+
{ name: 'offset', type: 'uint64' },
|
|
778
|
+
{ name: 'isLimited', type: 'bool' },
|
|
779
|
+
{ name: 'ref', type: 'bytes32' },
|
|
780
|
+
{
|
|
781
|
+
components: [
|
|
782
|
+
{ name: 'limit', type: 'uint256' },
|
|
783
|
+
{ name: 'used', type: 'uint256' },
|
|
784
|
+
],
|
|
785
|
+
name: 'usage',
|
|
786
|
+
type: 'tuple',
|
|
787
|
+
},
|
|
788
|
+
],
|
|
789
|
+
name: 'rules',
|
|
790
|
+
type: 'tuple[]',
|
|
791
|
+
},
|
|
792
|
+
{ name: 'packedNodes', type: 'uint256[]' },
|
|
793
|
+
],
|
|
794
|
+
name: 'paramRules',
|
|
795
|
+
type: 'tuple',
|
|
796
|
+
},
|
|
797
|
+
],
|
|
798
|
+
name: 'ActionConfig',
|
|
799
|
+
type: 'tuple',
|
|
800
|
+
},
|
|
801
|
+
], [
|
|
802
|
+
{
|
|
803
|
+
valueLimitPerUse: policy.valueLimitPerUse ?? 0n,
|
|
804
|
+
paramRules: {
|
|
805
|
+
rootNodeIndex,
|
|
806
|
+
rules,
|
|
807
|
+
packedNodes,
|
|
808
|
+
},
|
|
809
|
+
},
|
|
810
|
+
]),
|
|
811
|
+
};
|
|
812
|
+
}
|
|
677
813
|
case 'spending-limits': {
|
|
678
814
|
const tokens = policy.limits.map(({ token }) => token);
|
|
679
815
|
const limits = policy.limits.map(({ amount }) => amount);
|
|
680
816
|
return {
|
|
681
|
-
policy:
|
|
817
|
+
policy: addresses.spendingLimits,
|
|
682
818
|
initData: encodeAbiParameters([{ type: 'address[]' }, { type: 'uint256[]' }], [tokens, limits]),
|
|
683
819
|
};
|
|
684
820
|
}
|
|
685
821
|
case 'time-frame': {
|
|
822
|
+
// Deployed TimeFramePolicy slices initData[0:12] and unpacks as
|
|
823
|
+
// uint48 validUntil || uint48 validAfter (high 48 bits || low 48 bits).
|
|
686
824
|
return {
|
|
687
|
-
policy:
|
|
825
|
+
policy: addresses.timeFrame,
|
|
688
826
|
initData: encodePacked(['uint48', 'uint48'], [
|
|
689
827
|
Math.floor(policy.validUntil / 1000),
|
|
690
828
|
Math.floor(policy.validAfter / 1000),
|
|
@@ -693,13 +831,13 @@ function getPolicyData(policy, useDevContracts) {
|
|
|
693
831
|
}
|
|
694
832
|
case 'usage-limit': {
|
|
695
833
|
return {
|
|
696
|
-
policy:
|
|
834
|
+
policy: addresses.usageLimit,
|
|
697
835
|
initData: encodePacked(['uint128'], [policy.limit]),
|
|
698
836
|
};
|
|
699
837
|
}
|
|
700
838
|
case 'value-limit': {
|
|
701
839
|
return {
|
|
702
|
-
policy:
|
|
840
|
+
policy: addresses.valueLimit,
|
|
703
841
|
initData: encodeAbiParameters([{ type: 'uint256' }], [policy.limit]),
|
|
704
842
|
};
|
|
705
843
|
}
|
|
@@ -726,41 +864,47 @@ function getSmartSessionEmissaryAddress(useDevContracts) {
|
|
|
726
864
|
? SMART_SESSION_EMISSARY_ADDRESS_DEV
|
|
727
865
|
: SMART_SESSION_EMISSARY_ADDRESS;
|
|
728
866
|
}
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
function buildMockSignature(session, useDevContracts, chainCount = 1, targetChainId) {
|
|
867
|
+
function buildMockSignature(session, useDevContracts, chainCount = 1, targetChainId,
|
|
868
|
+
// Defaults to the historical first-use ENABLE shape.
|
|
869
|
+
shape = 'enable') {
|
|
870
|
+
// packSignature keys ENABLE vs USE on enableData *presence* within the
|
|
871
|
+
// verifyExecutions branch, and takes the ERC-1271 branch when verifyExecutions
|
|
872
|
+
// is false — so derive both from the requested shape.
|
|
873
|
+
const verifyExecutions = shape !== 'erc1271';
|
|
874
|
+
const includeEnableData = shape === 'enable';
|
|
738
875
|
const emissaryAddress = getSmartSessionEmissaryAddress(useDevContracts);
|
|
739
|
-
//
|
|
740
|
-
//
|
|
741
|
-
//
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
876
|
+
// Include enableData only when the session is actually being enabled (ENABLE
|
|
877
|
+
// shape) — its presence is what makes packSignature emit 0x01 vs 0x00, and it's
|
|
878
|
+
// ignored entirely by the USE / ERC-1271 shapes. Built lazily so steady-state
|
|
879
|
+
// shapes skip the chainId-entry allocation.
|
|
880
|
+
let enableData;
|
|
881
|
+
if (includeEnableData) {
|
|
882
|
+
// Use targetChainId when provided (per-chain mockSignatures path) so the mock
|
|
883
|
+
// emissary's chainId check passes on the correct chain. Falls back to
|
|
884
|
+
// session.chain.id for the global mockSignature (single-chain path).
|
|
885
|
+
const primaryChainId = targetChainId ?? session.chain.id;
|
|
886
|
+
// Normalize chainCount to a finite positive integer — guards against NaN/
|
|
887
|
+
// undefined from callers (e.g. `sourceChains?.length`) that would otherwise
|
|
888
|
+
// produce an empty array and silently drop the ChainId check.
|
|
889
|
+
const safeChainCount = Number.isFinite(chainCount) && chainCount > 0 ? Math.floor(chainCount) : 1;
|
|
890
|
+
// First entry is the real chain ID (for the ChainId check), the rest are
|
|
891
|
+
// chainId 0 placeholders. Hash mismatch is skipped by the mock emissary, so
|
|
892
|
+
// sessionDigest can be zeroHash throughout.
|
|
893
|
+
const hashesAndChainIds = Array.from({ length: safeChainCount }, (_, i) => ({
|
|
894
|
+
chainId: i === 0 ? BigInt(primaryChainId) : 0n,
|
|
895
|
+
sessionDigest: zeroHash,
|
|
896
|
+
}));
|
|
897
|
+
enableData = {
|
|
760
898
|
userSignature: `0x${'00'.repeat(65)}`,
|
|
761
899
|
hashesAndChainIds,
|
|
762
900
|
sessionToEnableIndex: 0,
|
|
763
|
-
}
|
|
901
|
+
};
|
|
902
|
+
}
|
|
903
|
+
const dummySigners = {
|
|
904
|
+
type: 'experimental_session',
|
|
905
|
+
session,
|
|
906
|
+
verifyExecutions,
|
|
907
|
+
...(enableData && { enableData }),
|
|
764
908
|
};
|
|
765
909
|
const dummyValidatorSignature = `0x${'00'.repeat(65)}`;
|
|
766
910
|
const sigData = packSignature(dummySigners, dummyValidatorSignature);
|
|
@@ -769,4 +913,4 @@ function buildMockSignature(session, useDevContracts, chainCount = 1, targetChai
|
|
|
769
913
|
function createFixedArray(length, getValue) {
|
|
770
914
|
return Array.from({ length }, (_, i) => getValue(i));
|
|
771
915
|
}
|
|
772
|
-
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, toSession, resolvePermit2ClaimPolicy, getSessionData, getPolicyData, getEnableSessionCall, getPermissionId, getSmartSessionValidator, getSessionDetails, isSessionEnabled, signEnableSession, buildMockSignature, };
|
|
916
|
+
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, ARG_POLICY_ADDRESS, USAGE_LIMIT_POLICY_ADDRESS, VALUE_LIMIT_POLICY_ADDRESS, INTENT_EXECUTION_POLICY_ADDRESS, packSignature, toSession, resolvePermit2ClaimPolicy, getSessionData, getPolicyData, getEnableSessionCall, getPermissionId, getSmartSessionValidator, getSessionDetails, isSessionEnabled, signEnableSession, buildMockSignature, };
|
|
@@ -1,7 +1,13 @@
|
|
|
1
|
-
type
|
|
1
|
+
type EvmCaip2ChainId = `eip155:${number}`;
|
|
2
|
+
type SolanaCaip2ChainId = `solana:${string}`;
|
|
3
|
+
type TronCaip2ChainId = `tron:${string}`;
|
|
4
|
+
type Caip2ChainId = EvmCaip2ChainId | SolanaCaip2ChainId | TronCaip2ChainId;
|
|
2
5
|
declare function toCaip2(chainId: number): Caip2ChainId;
|
|
3
6
|
declare function fromCaip2(chainId: string): number;
|
|
4
7
|
declare function isCaip2(chainId: string): chainId is Caip2ChainId;
|
|
5
|
-
|
|
6
|
-
|
|
8
|
+
declare function isEvmCaip2(chainId: string): chainId is EvmCaip2ChainId;
|
|
9
|
+
/** True when a numeric chain id corresponds to a known non-eip155 namespace. */
|
|
10
|
+
declare function isNonEvmChainId(chainId: number): boolean;
|
|
11
|
+
export type { Caip2ChainId, EvmCaip2ChainId, SolanaCaip2ChainId, TronCaip2ChainId, };
|
|
12
|
+
export { fromCaip2, isCaip2, isEvmCaip2, isNonEvmChainId, toCaip2 };
|
|
7
13
|
//# sourceMappingURL=caip2.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"caip2.d.ts","sourceRoot":"","sources":["../../../orchestrator/caip2.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"caip2.d.ts","sourceRoot":"","sources":["../../../orchestrator/caip2.ts"],"names":[],"mappings":"AAOA,KAAK,eAAe,GAAG,UAAU,MAAM,EAAE,CAAA;AACzC,KAAK,kBAAkB,GAAG,UAAU,MAAM,EAAE,CAAA;AAC5C,KAAK,gBAAgB,GAAG,QAAQ,MAAM,EAAE,CAAA;AACxC,KAAK,YAAY,GAAG,eAAe,GAAG,kBAAkB,GAAG,gBAAgB,CAAA;AAmB3E,iBAAS,OAAO,CAAC,OAAO,EAAE,MAAM,GAAG,YAAY,CAO9C;AAED,iBAAS,SAAS,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAS1C;AAED,iBAAS,OAAO,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,IAAI,YAAY,CAGzD;AAED,iBAAS,UAAU,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,IAAI,eAAe,CAE/D;AAED,gFAAgF;AAChF,iBAAS,eAAe,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAEjD;AAED,YAAY,EACV,YAAY,EACZ,eAAe,EACf,kBAAkB,EAClB,gBAAgB,GACjB,CAAA;AACD,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,UAAU,EAAE,eAAe,EAAE,OAAO,EAAE,CAAA"}
|
|
@@ -1,17 +1,52 @@
|
|
|
1
|
+
// CAIP-2 wire format. Mirrors the orchestrator's caip2.ts namespace registry
|
|
2
|
+
// — Solana / Tron synthetic numeric ids round-trip through the same CAIP-2
|
|
3
|
+
// strings the orchestrator emits, so the SDK and orchestrator agree on the
|
|
4
|
+
// wire shape without needing the user to think about CAIP-2 themselves.
|
|
5
|
+
//
|
|
6
|
+
// Spec: https://chainagnostic.org/CAIPs/caip-2
|
|
1
7
|
const EIP155_CAIP2_REGEX = /^eip155:\d+$/;
|
|
8
|
+
const NON_EIP155_CAIP2_REGEX = /^(?:solana|tron):[-_a-zA-Z0-9]{1,32}$/;
|
|
9
|
+
// Synthetic numeric ids ↔ CAIP-2 strings for non-eip155 chains. Must match
|
|
10
|
+
// the orchestrator's NON_EIP155_CAIP2_TO_ID exactly — these flow over the
|
|
11
|
+
// wire and any drift would cause routing failures.
|
|
12
|
+
const NON_EIP155_ID_TO_CAIP2 = {
|
|
13
|
+
792703809: 'solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp',
|
|
14
|
+
728126428: 'tron:0x2b6653dc',
|
|
15
|
+
};
|
|
16
|
+
const NON_EIP155_CAIP2_TO_ID = Object.fromEntries(Object.entries(NON_EIP155_ID_TO_CAIP2).map(([id, caip2]) => [
|
|
17
|
+
caip2,
|
|
18
|
+
Number(id),
|
|
19
|
+
]));
|
|
2
20
|
function toCaip2(chainId) {
|
|
3
21
|
if (!Number.isInteger(chainId) || chainId < 0) {
|
|
4
|
-
throw new Error(`Invalid
|
|
22
|
+
throw new Error(`Invalid chain id: ${chainId}`);
|
|
5
23
|
}
|
|
24
|
+
const nonEvm = NON_EIP155_ID_TO_CAIP2[chainId];
|
|
25
|
+
if (nonEvm)
|
|
26
|
+
return nonEvm;
|
|
6
27
|
return `eip155:${chainId}`;
|
|
7
28
|
}
|
|
8
29
|
function fromCaip2(chainId) {
|
|
9
|
-
if (
|
|
10
|
-
|
|
30
|
+
if (EIP155_CAIP2_REGEX.test(chainId)) {
|
|
31
|
+
return Number(chainId.slice('eip155:'.length));
|
|
11
32
|
}
|
|
12
|
-
|
|
33
|
+
if (NON_EIP155_CAIP2_REGEX.test(chainId)) {
|
|
34
|
+
const id = NON_EIP155_CAIP2_TO_ID[chainId];
|
|
35
|
+
if (id !== undefined)
|
|
36
|
+
return id;
|
|
37
|
+
}
|
|
38
|
+
throw new Error(`Invalid CAIP-2 chain id: ${chainId}`);
|
|
13
39
|
}
|
|
14
40
|
function isCaip2(chainId) {
|
|
41
|
+
if (EIP155_CAIP2_REGEX.test(chainId))
|
|
42
|
+
return true;
|
|
43
|
+
return chainId in NON_EIP155_CAIP2_TO_ID;
|
|
44
|
+
}
|
|
45
|
+
function isEvmCaip2(chainId) {
|
|
15
46
|
return EIP155_CAIP2_REGEX.test(chainId);
|
|
16
47
|
}
|
|
17
|
-
|
|
48
|
+
/** True when a numeric chain id corresponds to a known non-eip155 namespace. */
|
|
49
|
+
function isNonEvmChainId(chainId) {
|
|
50
|
+
return chainId in NON_EIP155_ID_TO_CAIP2;
|
|
51
|
+
}
|
|
52
|
+
export { fromCaip2, isCaip2, isEvmCaip2, isNonEvmChainId, toCaip2 };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { Address } from 'viem';
|
|
2
2
|
import type { AuthProvider } from '../auth/provider.js';
|
|
3
|
-
import type { IntentInput, IntentOpStatus, IntentSubmitRequestInternal, IntentSubmitResponse, Portfolio, QuoteResponse, SplitIntentsInput, SplitIntentsResult } from './types.js';
|
|
3
|
+
import type { IntentInput, IntentOpStatus, IntentSubmitRequestInternal, IntentSubmitResponse, Portfolio, QuoteResponse, SettlementLayerFilter, SplitIntentsInput, SplitIntentsResult } from './types.js';
|
|
4
4
|
interface PolicyContext {
|
|
5
5
|
intentInput: unknown;
|
|
6
6
|
isSponsored: boolean;
|
|
@@ -24,5 +24,6 @@ export declare class Orchestrator {
|
|
|
24
24
|
private getSubmitHeaders;
|
|
25
25
|
private fetch;
|
|
26
26
|
}
|
|
27
|
+
export declare function encodeSettlementLayers(filter: SettlementLayerFilter): readonly string[];
|
|
27
28
|
export {};
|
|
28
29
|
//# sourceMappingURL=client.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../../orchestrator/client.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../../orchestrator/client.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,MAAM,CAAA;AACnC,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAA;AAQpD,OAAO,KAAK,EAMV,WAAW,EACX,cAAc,EAEd,2BAA2B,EAC3B,oBAAoB,EACpB,SAAS,EAET,aAAa,EACb,qBAAqB,EACrB,iBAAiB,EACjB,kBAAkB,EAEnB,MAAM,SAAS,CAAA;AAGhB,UAAU,aAAa;IACrB,WAAW,EAAE,OAAO,CAAA;IACpB,WAAW,EAAE,OAAO,CAAA;CACrB;AAED,qBAAa,YAAY;IACvB,OAAO,CAAC,SAAS,CAAQ;IACzB,OAAO,CAAC,YAAY,CAAc;IAClC,OAAO,CAAC,YAAY,CAAC,CAAwB;gBAG3C,SAAS,EAAE,MAAM,EACjB,YAAY,EAAE,YAAY,EAC1B,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC;IAO5B,YAAY,CAChB,cAAc,EAAE,OAAO,EACvB,MAAM,CAAC,EAAE;QACP,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAA;QACnB,MAAM,CAAC,EAAE;YAAE,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,EAAE,CAAA;SAAE,CAAA;KAC1C,GACA,OAAO,CAAC,SAAS,CAAC;IAyCf,WAAW,CAAC,KAAK,EAAE,WAAW,GAAG,OAAO,CAAC,aAAa,CAAC;IAUvD,QAAQ,CAAC,KAAK,EAAE,iBAAiB,GAAG,OAAO,CAAC,kBAAkB,CAAC;IAqB/D,YAAY,CAChB,OAAO,EAAE,2BAA2B,EACpC,aAAa,CAAC,EAAE,aAAa,GAC5B,OAAO,CAAC,oBAAoB,CAAC;IAe1B,SAAS,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,cAAc,CAAC;YAgB5C,UAAU;YAWV,gBAAgB;YAiBhB,KAAK;CA8BpB;AA4HD,wBAAgB,sBAAsB,CACpC,MAAM,EAAE,qBAAqB,GAC5B,SAAS,MAAM,EAAE,CAInB"}
|