Skip to content

Commit 9a6c7cd

Browse files
committed
add missing promptToCreateSolanaAccount flag
1 parent 1f9c597 commit 9a6c7cd

File tree

2 files changed

+276
-68
lines changed

2 files changed

+276
-68
lines changed

packages/multichain-api-middleware/src/handlers/wallet-createSession.test.ts

Lines changed: 222 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -673,34 +673,37 @@ describe('wallet_createSession', () => {
673673

674674
await handler(baseRequest);
675675

676-
expect(requestPermissionsForOrigin).toHaveBeenCalledWith({
677-
[Caip25EndowmentPermissionName]: {
678-
caveats: [
679-
{
680-
type: Caip25CaveatType,
681-
value: {
682-
requiredScopes: {
683-
'eip155:1337': {
684-
accounts: ['eip155:1337:0x1', 'eip155:1337:0x3'],
685-
},
686-
},
687-
optionalScopes: {
688-
'eip155:100': {
689-
accounts: ['eip155:100:0x1', 'eip155:100:0x3'],
676+
expect(requestPermissionsForOrigin).toHaveBeenCalledWith(
677+
{
678+
[Caip25EndowmentPermissionName]: {
679+
caveats: [
680+
{
681+
type: Caip25CaveatType,
682+
value: {
683+
requiredScopes: {
684+
'eip155:1337': {
685+
accounts: ['eip155:1337:0x1', 'eip155:1337:0x3'],
686+
},
690687
},
691-
[MultichainNetwork.Solana]: {
692-
accounts: [
693-
'solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp:EEivRh9T4GTLEJprEaKQyjSQzW13JRb5D7jSpvPQ8296',
694-
],
688+
optionalScopes: {
689+
'eip155:100': {
690+
accounts: ['eip155:100:0x1', 'eip155:100:0x3'],
691+
},
692+
[MultichainNetwork.Solana]: {
693+
accounts: [
694+
'solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp:EEivRh9T4GTLEJprEaKQyjSQzW13JRb5D7jSpvPQ8296',
695+
],
696+
},
695697
},
698+
isMultichainOrigin: true,
699+
sessionProperties: {},
696700
},
697-
isMultichainOrigin: true,
698-
sessionProperties: {},
699701
},
700-
},
701-
],
702+
],
703+
},
702704
},
703-
});
705+
{ metadata: { promptToCreateSolanaAccount: false } },
706+
);
704707
});
705708

706709
it('throws an error when requesting account permission approval fails', async () => {
@@ -799,29 +802,32 @@ describe('wallet_createSession', () => {
799802
unsupportableScopes: {},
800803
});
801804
await handler(baseRequest);
802-
expect(requestPermissionsForOrigin).toHaveBeenCalledWith({
803-
[Caip25EndowmentPermissionName]: {
804-
caveats: [
805-
{
806-
type: Caip25CaveatType,
807-
value: {
808-
requiredScopes: {
809-
'eip155:1337': {
810-
accounts: ['eip155:1337:0x1', 'eip155:1337:0x3'],
805+
expect(requestPermissionsForOrigin).toHaveBeenCalledWith(
806+
{
807+
[Caip25EndowmentPermissionName]: {
808+
caveats: [
809+
{
810+
type: Caip25CaveatType,
811+
value: {
812+
requiredScopes: {
813+
'eip155:1337': {
814+
accounts: ['eip155:1337:0x1', 'eip155:1337:0x3'],
815+
},
811816
},
812-
},
813-
optionalScopes: {
814-
'eip155:100': {
815-
accounts: ['eip155:100:0x1', 'eip155:100:0x3'],
817+
optionalScopes: {
818+
'eip155:100': {
819+
accounts: ['eip155:100:0x1', 'eip155:100:0x3'],
820+
},
816821
},
822+
isMultichainOrigin: true,
823+
sessionProperties: {},
817824
},
818-
isMultichainOrigin: true,
819-
sessionProperties: {},
820825
},
821-
},
822-
],
826+
],
827+
},
823828
},
824-
});
829+
{ metadata: { promptToCreateSolanaAccount: false } },
830+
);
825831
});
826832

827833
it('preserves known session properties', async () => {
@@ -993,32 +999,189 @@ describe('wallet_createSession', () => {
993999
},
9941000
});
9951001

996-
expect(requestPermissionsForOrigin).toHaveBeenCalledWith({
997-
[Caip25EndowmentPermissionName]: {
998-
caveats: [
999-
{
1000-
type: Caip25CaveatType,
1001-
value: {
1002-
requiredScopes: {
1003-
'eip155:1': {
1004-
accounts: ['eip155:1:0xABC123'], // Requested EVM address included
1002+
expect(requestPermissionsForOrigin).toHaveBeenCalledWith(
1003+
{
1004+
[Caip25EndowmentPermissionName]: {
1005+
caveats: [
1006+
{
1007+
type: Caip25CaveatType,
1008+
value: {
1009+
requiredScopes: {
1010+
'eip155:1': {
1011+
accounts: ['eip155:1:0xABC123'], // Requested EVM address included
1012+
},
10051013
},
1014+
optionalScopes: {
1015+
[MultichainNetwork.Solana]: {
1016+
accounts: [], // Solana address excluded due to case mismatch
1017+
},
1018+
[MultichainNetwork.Bitcoin]: {
1019+
accounts: [], // Bitcoin address excluded due to case mismatch
1020+
},
1021+
},
1022+
isMultichainOrigin: true,
1023+
sessionProperties: {},
10061024
},
1007-
optionalScopes: {
1008-
[MultichainNetwork.Solana]: {
1009-
accounts: [], // Solana address excluded due to case mismatch
1025+
},
1026+
],
1027+
},
1028+
},
1029+
{ metadata: { promptToCreateSolanaAccount: false } },
1030+
);
1031+
});
1032+
});
1033+
1034+
describe('promptToCreateSolanaAccount', () => {
1035+
const baseRequestWithSolanaScope = {
1036+
jsonrpc: '2.0' as const,
1037+
id: 0,
1038+
method: 'wallet_createSession',
1039+
origin: 'http://test.com',
1040+
params: {
1041+
optionalScopes: {
1042+
[MultichainNetwork.Solana]: {
1043+
methods: [],
1044+
notifications: [],
1045+
accounts: [],
1046+
},
1047+
},
1048+
sessionProperties: {
1049+
[KnownSessionProperties.SolanaAccountChangedNotifications]: true,
1050+
},
1051+
},
1052+
};
1053+
1054+
it('prompts to create a solana account if a solana scope is requested and no solana accounts are currently available', async () => {
1055+
const {
1056+
handler,
1057+
requestPermissionsForOrigin,
1058+
getNonEvmAccountAddresses,
1059+
} = createMockedHandler();
1060+
getNonEvmAccountAddresses.mockReturnValue([]);
1061+
MockChainAgnosticPermission.validateAndNormalizeScopes.mockReturnValue({
1062+
normalizedRequiredScopes: {
1063+
[MultichainNetwork.Solana]: {
1064+
methods: [],
1065+
notifications: [],
1066+
accounts: [],
1067+
},
1068+
},
1069+
normalizedOptionalScopes: {},
1070+
});
1071+
1072+
MockChainAgnosticPermission.bucketScopes
1073+
.mockReturnValueOnce({
1074+
supportedScopes: {},
1075+
supportableScopes: {},
1076+
unsupportableScopes: {},
1077+
})
1078+
.mockReturnValueOnce({
1079+
supportedScopes: {
1080+
'eip155:1337': {
1081+
methods: [],
1082+
notifications: [],
1083+
accounts: [],
1084+
},
1085+
},
1086+
supportableScopes: {},
1087+
unsupportableScopes: {},
1088+
});
1089+
1090+
await handler(baseRequestWithSolanaScope);
1091+
1092+
expect(requestPermissionsForOrigin).toHaveBeenCalledWith(
1093+
{
1094+
[Caip25EndowmentPermissionName]: {
1095+
caveats: [
1096+
{
1097+
type: Caip25CaveatType,
1098+
value: {
1099+
requiredScopes: {},
1100+
optionalScopes: {
1101+
'eip155:1337': {
1102+
accounts: [],
1103+
},
10101104
},
1011-
[MultichainNetwork.Bitcoin]: {
1012-
accounts: [], // Bitcoin address excluded due to case mismatch
1105+
isMultichainOrigin: true,
1106+
sessionProperties: {
1107+
[KnownSessionProperties.SolanaAccountChangedNotifications]:
1108+
true,
10131109
},
10141110
},
1015-
isMultichainOrigin: true,
1016-
sessionProperties: {},
10171111
},
1018-
},
1019-
],
1112+
],
1113+
},
1114+
},
1115+
{ metadata: { promptToCreateSolanaAccount: true } },
1116+
);
1117+
});
1118+
1119+
it('does not prompt to create a solana account if a solana scope is requested and solana accounts are currently available', async () => {
1120+
const {
1121+
handler,
1122+
requestPermissionsForOrigin,
1123+
getNonEvmAccountAddresses,
1124+
} = createMockedHandler();
1125+
getNonEvmAccountAddresses.mockReturnValue([
1126+
'solana:101:0x1',
1127+
'solana:101:0x2',
1128+
]);
1129+
MockChainAgnosticPermission.validateAndNormalizeScopes.mockReturnValue({
1130+
normalizedRequiredScopes: {},
1131+
normalizedOptionalScopes: {
1132+
[MultichainNetwork.Solana]: {
1133+
methods: [],
1134+
notifications: [],
1135+
accounts: [],
1136+
},
10201137
},
10211138
});
1139+
1140+
MockChainAgnosticPermission.bucketScopes
1141+
.mockReturnValueOnce({
1142+
supportedScopes: {},
1143+
supportableScopes: {},
1144+
unsupportableScopes: {},
1145+
})
1146+
.mockReturnValueOnce({
1147+
supportedScopes: {
1148+
[MultichainNetwork.Solana]: {
1149+
methods: [],
1150+
notifications: [],
1151+
accounts: [],
1152+
},
1153+
},
1154+
supportableScopes: {},
1155+
unsupportableScopes: {},
1156+
});
1157+
1158+
await handler(baseRequestWithSolanaScope);
1159+
1160+
expect(requestPermissionsForOrigin).toHaveBeenCalledWith(
1161+
{
1162+
[Caip25EndowmentPermissionName]: {
1163+
caveats: [
1164+
{
1165+
type: Caip25CaveatType,
1166+
value: {
1167+
requiredScopes: {},
1168+
optionalScopes: {
1169+
[MultichainNetwork.Solana]: {
1170+
accounts: [],
1171+
},
1172+
},
1173+
isMultichainOrigin: true,
1174+
sessionProperties: {
1175+
[KnownSessionProperties.SolanaAccountChangedNotifications]:
1176+
true,
1177+
},
1178+
},
1179+
},
1180+
],
1181+
},
1182+
},
1183+
{ metadata: { promptToCreateSolanaAccount: false } },
1184+
);
10221185
});
10231186
});
10241187
});

0 commit comments

Comments
 (0)