Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: added initial provider authorize error rule #26828

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,10 @@ lavamoat/**/policy-debug.json
# Attributions
licenseInfos.json

# Branding
/app/images/branding

# API Spec tests
html-report/
html-report-multichain/

/app/images/branding

Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ const dereffedPromise = dereferenceDocument(
);
export const multichainMethodCallValidator = async (
method: string,
params: JsonRpcParams,
params: JsonRpcParams | undefined,
) => {
const dereffed = await dereffedPromise;
const methodToCheck = dereffed.methods.find(
Expand All @@ -55,20 +55,22 @@ export const multichainMethodCallValidator = async (
const errors: JsonRpcError[] = [];
// check each param and aggregate errors
(methodToCheck as unknown as MethodObject).params.forEach((param, i) => {
let paramToCheck: Json;
let paramToCheck: Json | undefined;
const p = param as ContentDescriptorObject;
if (isObject(params)) {
paramToCheck = params[p.name];
} else {
} else if (params && Array.isArray(params)) {
paramToCheck = params[i];
} else {
paramToCheck = undefined;
}
const result = v.validate(paramToCheck, p.schema as unknown as Schema, {
required: true,
required: p.required,
shanejonas marked this conversation as resolved.
Show resolved Hide resolved
});
if (result.errors) {
errors.push(
...result.errors.map((e) => {
return transformError(e, p, paramToCheck);
return transformError(e, p, paramToCheck) as JsonRpcError;
}),
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export async function walletCreateSessionHandler(req, res, _next, end, hooks) {

if (sessionProperties && Object.keys(sessionProperties).length === 0) {
return end(
new EthereumRpcError(5300, 'Invalid Session Properties requested'),
new EthereumRpcError(5302, 'Invalid sessionProperties requested'),
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ describe('wallet_createSession', () => {
},
});
expect(end).toHaveBeenCalledWith(
new EthereumRpcError(5300, 'Invalid Session Properties requested'),
new EthereumRpcError(5302, 'Invalid sessionProperties requested'),
);
});

Expand Down
4 changes: 2 additions & 2 deletions app/scripts/metamask-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ import {
Caip25CaveatType,
Caip25EndowmentPermissionName,
} from './lib/multichain-api/caip25permissions';
// import { multichainMethodCallValidatorMiddleware } from './lib/multichain-api/multichainMethodCallValidator';
import { multichainMethodCallValidatorMiddleware } from './lib/multichain-api/multichainMethodCallValidator';

import { decodeTransactionData } from './lib/transaction/decode/util';
import MultichainSubscriptionManager from './lib/multichain-api/MultichainSubscriptionManager';
Expand Down Expand Up @@ -5970,7 +5970,7 @@ export default class MetamaskController extends EventEmitter {
});

// TODO: Uncomment this when wallet lifecycle methods are added to api-specs
// engine.push(multichainMethodCallValidatorMiddleware);
engine.push(multichainMethodCallValidatorMiddleware);

engine.push(
createScaffoldMiddleware({
Expand Down
73 changes: 67 additions & 6 deletions lavamoat/browserify/beta/policy.json
Original file line number Diff line number Diff line change
Expand Up @@ -1608,9 +1608,9 @@
"@metamask/controller-utils": true,
"@metamask/eth-sig-util": true,
"@metamask/message-manager>@metamask/base-controller": true,
"@metamask/message-manager>jsonschema": true,
"@metamask/utils": true,
"browserify>buffer": true,
"jsonschema": true,
"uuid": true,
"webpack>events": true
}
Expand All @@ -1623,11 +1623,6 @@
"immer": true
}
},
"@metamask/message-manager>jsonschema": {
"packages": {
"browserify>url": true
}
},
"@metamask/message-signing-snap>@noble/ciphers": {
"globals": {
"TextDecoder": true,
Expand Down Expand Up @@ -3099,6 +3094,62 @@
"crypto": true
}
},
"@open-rpc/schema-utils-js": {
"packages": {
"@open-rpc/meta-schema": true,
"@open-rpc/schema-utils-js>@json-schema-tools/dereferencer": true,
"@open-rpc/schema-utils-js>@json-schema-tools/meta-schema": true,
"@open-rpc/schema-utils-js>@json-schema-tools/reference-resolver": true,
"@open-rpc/schema-utils-js>ajv": true,
"@open-rpc/schema-utils-js>is-url": true,
"eth-rpc-errors>fast-safe-stringify": true
}
},
"@open-rpc/schema-utils-js>@json-schema-tools/dereferencer": {
"packages": {
"@open-rpc/schema-utils-js>@json-schema-tools/dereferencer>@json-schema-tools/traverse": true,
"@open-rpc/schema-utils-js>@json-schema-tools/reference-resolver": true,
"eth-rpc-errors>fast-safe-stringify": true
}
},
"@open-rpc/schema-utils-js>@json-schema-tools/reference-resolver": {
"packages": {
"@open-rpc/schema-utils-js>@json-schema-tools/reference-resolver>@json-schema-spec/json-pointer": true,
"@open-rpc/test-coverage>isomorphic-fetch": true
}
},
"@open-rpc/schema-utils-js>ajv": {
"globals": {
"console": true
},
"packages": {
"@metamask/snaps-utils>fast-json-stable-stringify": true,
"@open-rpc/schema-utils-js>ajv>json-schema-traverse": true,
"eslint>ajv>uri-js": true,
"eslint>fast-deep-equal": true
}
},
"@open-rpc/test-coverage>isomorphic-fetch": {
"globals": {
"fetch.bind": true
},
"packages": {
"@open-rpc/test-coverage>isomorphic-fetch>whatwg-fetch": true
}
},
"@open-rpc/test-coverage>isomorphic-fetch>whatwg-fetch": {
"globals": {
"AbortController": true,
"Blob": true,
"FileReader": true,
"FormData": true,
"URLSearchParams.prototype.isPrototypeOf": true,
"XMLHttpRequest": true,
"console.warn": true,
"define": true,
"setTimeout": true
}
},
"@popperjs/core": {
"globals": {
"Element": true,
Expand Down Expand Up @@ -3982,6 +4033,11 @@
"koa>is-generator-function>has-tostringtag": true
}
},
"eslint>ajv>uri-js": {
"globals": {
"define": true
}
},
"eth-ens-namehash": {
"globals": {
"name": "write"
Expand Down Expand Up @@ -4454,6 +4510,11 @@
"readable-stream": true
}
},
"jsonschema": {
"packages": {
"browserify>url": true
}
},
"koa>content-disposition>safe-buffer": {
"packages": {
"browserify>buffer": true
Expand Down
73 changes: 67 additions & 6 deletions lavamoat/browserify/flask/policy.json
Original file line number Diff line number Diff line change
Expand Up @@ -1608,9 +1608,9 @@
"@metamask/controller-utils": true,
"@metamask/eth-sig-util": true,
"@metamask/message-manager>@metamask/base-controller": true,
"@metamask/message-manager>jsonschema": true,
"@metamask/utils": true,
"browserify>buffer": true,
"jsonschema": true,
"uuid": true,
"webpack>events": true
}
Expand All @@ -1623,11 +1623,6 @@
"immer": true
}
},
"@metamask/message-manager>jsonschema": {
"packages": {
"browserify>url": true
}
},
"@metamask/message-signing-snap>@noble/ciphers": {
"globals": {
"TextDecoder": true,
Expand Down Expand Up @@ -3099,6 +3094,62 @@
"crypto": true
}
},
"@open-rpc/schema-utils-js": {
"packages": {
"@open-rpc/meta-schema": true,
"@open-rpc/schema-utils-js>@json-schema-tools/dereferencer": true,
"@open-rpc/schema-utils-js>@json-schema-tools/meta-schema": true,
"@open-rpc/schema-utils-js>@json-schema-tools/reference-resolver": true,
"@open-rpc/schema-utils-js>ajv": true,
"@open-rpc/schema-utils-js>is-url": true,
"eth-rpc-errors>fast-safe-stringify": true
}
},
"@open-rpc/schema-utils-js>@json-schema-tools/dereferencer": {
"packages": {
"@open-rpc/schema-utils-js>@json-schema-tools/dereferencer>@json-schema-tools/traverse": true,
"@open-rpc/schema-utils-js>@json-schema-tools/reference-resolver": true,
"eth-rpc-errors>fast-safe-stringify": true
}
},
"@open-rpc/schema-utils-js>@json-schema-tools/reference-resolver": {
"packages": {
"@open-rpc/schema-utils-js>@json-schema-tools/reference-resolver>@json-schema-spec/json-pointer": true,
"@open-rpc/test-coverage>isomorphic-fetch": true
}
},
"@open-rpc/schema-utils-js>ajv": {
"globals": {
"console": true
},
"packages": {
"@metamask/snaps-utils>fast-json-stable-stringify": true,
"@open-rpc/schema-utils-js>ajv>json-schema-traverse": true,
"eslint>ajv>uri-js": true,
"eslint>fast-deep-equal": true
}
},
"@open-rpc/test-coverage>isomorphic-fetch": {
"globals": {
"fetch.bind": true
},
"packages": {
"@open-rpc/test-coverage>isomorphic-fetch>whatwg-fetch": true
}
},
"@open-rpc/test-coverage>isomorphic-fetch>whatwg-fetch": {
"globals": {
"AbortController": true,
"Blob": true,
"FileReader": true,
"FormData": true,
"URLSearchParams.prototype.isPrototypeOf": true,
"XMLHttpRequest": true,
"console.warn": true,
"define": true,
"setTimeout": true
}
},
"@popperjs/core": {
"globals": {
"Element": true,
Expand Down Expand Up @@ -3982,6 +4033,11 @@
"koa>is-generator-function>has-tostringtag": true
}
},
"eslint>ajv>uri-js": {
"globals": {
"define": true
}
},
"eth-ens-namehash": {
"globals": {
"name": "write"
Expand Down Expand Up @@ -4454,6 +4510,11 @@
"readable-stream": true
}
},
"jsonschema": {
"packages": {
"browserify>url": true
}
},
"koa>content-disposition>safe-buffer": {
"packages": {
"browserify>buffer": true
Expand Down
Loading