Skip to content

Commit

Permalink
Merge branch 'caip-multichain' into jl/caip-multichain/fix-provider-r…
Browse files Browse the repository at this point in the history
…equest-scopeObject-check
  • Loading branch information
jiexi authored Jul 18, 2024
2 parents 6670adc + c8dad3d commit ce0efff
Show file tree
Hide file tree
Showing 8 changed files with 11 additions and 289 deletions.
16 changes: 7 additions & 9 deletions app/scripts/lib/multichain-api/scope/assert.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,15 +138,13 @@ describe('Scope Assert', () => {
describe('assertScopesSupported', () => {
const findNetworkClientIdByChainId = jest.fn();

it('throws an error if no scopes are defined', () => {
expect(() => {
assertScopesSupported(
{},
{
findNetworkClientIdByChainId,
},
);
}).toThrow(new EthereumRpcError(5100, 'Unknown error with request'));
it('does not throw an error if no scopes are defined', () => {
assertScopesSupported(
{},
{
findNetworkClientIdByChainId,
},
);
});

it('throws an error if any scope is invalid', () => {
Expand Down
8 changes: 0 additions & 8 deletions app/scripts/lib/multichain-api/scope/assert.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,6 @@ export const assertScopesSupported = (
findNetworkClientIdByChainId: (chainId: Hex) => NetworkClientId;
},
) => {
// TODO: Should we be less strict validating optional scopes? As in we can
// drop parts or the entire optional scope when we hit something invalid which
// is not true for the required scopes.

if (Object.keys(scopes).length === 0) {
throw new EthereumRpcError(5000, 'Unknown error with request');
}

for (const [scopeString, scopeObject] of Object.entries(scopes)) {
assertScopeSupported(scopeString, scopeObject, {
findNetworkClientIdByChainId,
Expand Down
20 changes: 4 additions & 16 deletions app/scripts/lib/multichain-api/scope/validation.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,24 +151,12 @@ describe('Scope Validation', () => {
accounts: [],
};

it('throws an error if required scopes are defined but none are valid', () => {
expect(() =>
validateScopes({ 'eip155:1': {} as unknown as ScopeObject }, undefined),
).toThrow(
new Error(
'`requiredScopes` object MUST contain 1 more `scopeObjects`, if present',
),
);
it('does not throw an error if required scopes are defined but none are valid', () => {
validateScopes({ 'eip155:1': {} as unknown as ScopeObject }, undefined);
});

it('throws an error if optional scopes are defined but none are valid', () => {
expect(() =>
validateScopes(undefined, { 'eip155:1': {} as unknown as ScopeObject }),
).toThrow(
new Error(
'`optionalScopes` object MUST contain 1 more `scopeObjects`, if present',
),
);
it('does not throw an error if optional scopes are defined but none are valid', () => {
validateScopes(undefined, { 'eip155:1': {} as unknown as ScopeObject });
});

it('returns the valid required and optional scopes', () => {
Expand Down
12 changes: 0 additions & 12 deletions app/scripts/lib/multichain-api/scope/validation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,6 @@ export const validateScopes = (
};
}
}
if (requiredScopes && Object.keys(validRequiredScopes).length === 0) {
// What error code and message here?
throw new Error(
'`requiredScopes` object MUST contain 1 more `scopeObjects`, if present',
);
}

const validOptionalScopes: ScopesObject = {};
for (const [scopeString, scopeObject] of Object.entries(
Expand All @@ -108,12 +102,6 @@ export const validateScopes = (
};
}
}
if (optionalScopes && Object.keys(validOptionalScopes).length === 0) {
// What error code and message here?
throw new Error(
'`optionalScopes` object MUST contain 1 more `scopeObjects`, if present',
);
}

return {
validRequiredScopes,
Expand Down
61 changes: 0 additions & 61 deletions lavamoat/browserify/beta/policy.json
Original file line number Diff line number Diff line change
Expand Up @@ -3007,62 +3007,6 @@
"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 @@ -3875,11 +3819,6 @@
"koa>is-generator-function>has-tostringtag": true
}
},
"eslint>ajv>uri-js": {
"globals": {
"define": true
}
},
"eslint>optionator>fast-levenshtein": {
"globals": {
"Intl": true,
Expand Down
61 changes: 0 additions & 61 deletions lavamoat/browserify/flask/policy.json
Original file line number Diff line number Diff line change
Expand Up @@ -3007,62 +3007,6 @@
"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 @@ -3875,11 +3819,6 @@
"koa>is-generator-function>has-tostringtag": true
}
},
"eslint>ajv>uri-js": {
"globals": {
"define": true
}
},
"eslint>optionator>fast-levenshtein": {
"globals": {
"Intl": true,
Expand Down
61 changes: 0 additions & 61 deletions lavamoat/browserify/main/policy.json
Original file line number Diff line number Diff line change
Expand Up @@ -3007,62 +3007,6 @@
"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 @@ -3875,11 +3819,6 @@
"koa>is-generator-function>has-tostringtag": true
}
},
"eslint>ajv>uri-js": {
"globals": {
"define": true
}
},
"eslint>optionator>fast-levenshtein": {
"globals": {
"Intl": true,
Expand Down
61 changes: 0 additions & 61 deletions lavamoat/browserify/mmi/policy.json
Original file line number Diff line number Diff line change
Expand Up @@ -3099,62 +3099,6 @@
"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 @@ -3967,11 +3911,6 @@
"koa>is-generator-function>has-tostringtag": true
}
},
"eslint>ajv>uri-js": {
"globals": {
"define": true
}
},
"eslint>optionator>fast-levenshtein": {
"globals": {
"Intl": true,
Expand Down

0 comments on commit ce0efff

Please sign in to comment.