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

feat: Add CAIP-25 permission and adapters to @metamask/multichain #4784

Merged
merged 169 commits into from
Nov 13, 2024
Merged
Show file tree
Hide file tree
Changes from 165 commits
Commits
Show all changes
169 commits
Select commit Hold shift + click to select a range
bc56104
Initial package
jiexi Oct 10, 2024
a4b52ad
Fix caip25Permission
jiexi Oct 10, 2024
86ab58a
scopes
jiexi Oct 10, 2024
186d4b3
Fix middlewares
jiexi Oct 10, 2024
6a93d1d
Fix adapters except permission middleware
jiexi Oct 10, 2024
231bcaa
Rename handlers js to ts
jiexi Oct 10, 2024
4e52fc0
permission middleware test js ts rename
jiexi Oct 10, 2024
151eaac
fix: typescript + linting (#4788)
shanejonas Oct 11, 2024
85a723e
Added exports for multichain package (#4789)
shanejonas Oct 11, 2024
a0bb278
Add requires
jiexi Oct 11, 2024
1cd8ef2
add permittedChains adapter to exports
jiexi Oct 11, 2024
c636def
kill scope index barrel
jiexi Oct 11, 2024
a6aa7c1
barrel
jiexi Oct 14, 2024
42134f7
Merge branch 'main' into caip-multichain
jiexi Oct 14, 2024
a13b9c7
remove subjectTypes from CAIP-25 permission
jiexi Oct 14, 2024
81db877
update eth accounts adapter with empty wallet and wallet:eip155 Scope…
jiexi Oct 14, 2024
a3fc263
fix caip25permission spec
jiexi Oct 14, 2024
afe5cb9
upsert empty wallet:eip155 when setting permittedChains
jiexi Oct 14, 2024
9ea78be
lint
jiexi Oct 14, 2024
5650d31
Rename scope.test.ts to types.test.ts
jiexi Oct 14, 2024
df5167e
add networkClientId type to permission-adapter-middleware
jiexi Oct 15, 2024
9446b0b
fix snapshot
jiexi Oct 15, 2024
f65ca24
Merge branch 'main' into caip-multichain
jiexi Oct 15, 2024
941849d
add KnownWalletScopeString enum
jiexi Oct 15, 2024
a250de2
stop upserting wallet scope in setEthAccounts()
jiexi Oct 15, 2024
aa7ba39
lint
jiexi Oct 15, 2024
8415be6
update removeScope mutator to not revoke permission if requiredScope …
jiexi Oct 15, 2024
c7f510e
Fix specificationBuilder jsdoc and typing
jiexi Oct 15, 2024
4afa8f8
Fix caip25permission type
jiexi Oct 15, 2024
597e837
Fix caip25permission type
jiexi Oct 15, 2024
1872188
small dry todo fix
adonesky1 Oct 15, 2024
c5d8005
another small dry
adonesky1 Oct 15, 2024
54f7c49
Added handler wrappers to better integrate with existing middleware (…
shanejonas Oct 15, 2024
ada451d
change subscriptionManager require to import
jiexi Oct 15, 2024
2322e39
lint
jiexi Oct 15, 2024
9b21677
Merge branch 'main' into caip-multichain
jiexi Oct 16, 2024
00a41cb
Jl/caip multichain/update scope object account types (#4803)
jiexi Oct 16, 2024
f30dd8b
update @metamask/rpc-errors version
adonesky1 Oct 17, 2024
71085a0
fix merge
adonesky1 Oct 17, 2024
f2be8f0
Merge branch 'main' into caip-multichain
jiexi Oct 17, 2024
644f4d0
Add isEqualCaseInsensitive to controller-utils
jiexi Oct 17, 2024
1b78bbc
create initial multichain package
jiexi Oct 17, 2024
fc28c89
remove API related logic
jiexi Oct 17, 2024
ba25ce5
Merge branch 'initialize-caip-multichain' into caip-multichain
jiexi Oct 17, 2024
4ceb118
remove api related deps
jiexi Oct 17, 2024
9bcf869
Fix package.json
jiexi Oct 17, 2024
633485c
Merge branch 'initialize-caip-multichain' into caip-multichain
jiexi Oct 17, 2024
afb2e2c
fix bad merge
jiexi Oct 17, 2024
109a7bf
Update packages/controller-utils/src/util.test.ts
jiexi Oct 17, 2024
1e67641
Merge branch 'controller-utils-isEqualCaseInsensitive' into initializ…
jiexi Oct 17, 2024
32b213a
Merge branch 'initialize-caip-multichain' into caip-multichain
jiexi Oct 17, 2024
dae4f73
add account support check in validator (#4816)
jiexi Oct 17, 2024
d7ed999
Merge branch 'main' into initialize-caip-multichain
jiexi Oct 21, 2024
b4b65e2
Merge branch 'initialize-caip-multichain' into caip-multichain
jiexi Oct 21, 2024
fad338d
remove caip-permission-adapter-middleware
jiexi Oct 21, 2024
c5980c6
remove caip-permission-adapter-middleware from exports
jiexi Oct 21, 2024
a7a8e6e
remove types/@metamask/eth-json-rpc-filters.d.ts
jiexi Oct 21, 2024
6b367f0
Merge branch 'main' into caip-multichain
adonesky1 Oct 21, 2024
42297f9
add back readme content
adonesky1 Oct 21, 2024
26acfcd
Merge branch 'main' into initialize-caip-multichain
jiexi Oct 21, 2024
2e3bfb4
Merge branch 'initialize-caip-multichain' into caip-multichain
jiexi Oct 21, 2024
7203358
bump network-controller dep
jiexi Oct 22, 2024
046133a
add Scoped Properties to Caip25Authorization type
jiexi Oct 22, 2024
eea9f46
Merge branch 'main' into caip-multichain
jiexi Oct 22, 2024
67b222e
Fix ScopedProperties type
jiexi Oct 22, 2024
009fb4a
Loosen get adapter param types (#4835)
jiexi Oct 22, 2024
0631c48
Seperate types and constants
jiexi Oct 23, 2024
4685547
Merge branch 'main' into caip-multichain
jiexi Oct 23, 2024
18d1112
remove jest.resetAllMocks
jiexi Oct 23, 2024
1ba77c7
yarn lock
jiexi Oct 23, 2024
bb50a19
yarn
jiexi Oct 23, 2024
7d32a0b
100% coverage
jiexi Oct 23, 2024
f095370
Remove accountsChanged and chainChanged from KnownNotifications (sinc…
jiexi Oct 23, 2024
62929a4
Merge branch 'main' into caip-multichain
jiexi Oct 23, 2024
491552f
Update packages/multichain/src/scope/transform.test.ts
jiexi Oct 24, 2024
bd0f50f
Merge branch 'main' into caip-multichain
jiexi Oct 24, 2024
cad5e3e
Merge branch 'main' into caip-multichain
jiexi Oct 28, 2024
757b177
align deps
jiexi Oct 28, 2024
dcb593b
rename Caip25CaveatFactoryFn to createCaip25Caveat
jiexi Oct 28, 2024
16aa686
switch removeScope param order
jiexi Oct 28, 2024
f8b887c
switch removeAccount param order
jiexi Oct 28, 2024
632db4b
do not export removeScope directly. fix Caip25CaveatMutatorFactories …
jiexi Oct 28, 2024
628a38c
reorder removeAccountOnScope params
jiexi Oct 28, 2024
6346955
rename Caip25CaveatMutatorFactories to Caip25CaveatMutators
jiexi Oct 28, 2024
d40d63d
fix barrel export
jiexi Oct 28, 2024
d75d5d6
replace node assert with lodash.isEqual
jiexi Oct 28, 2024
23d10ed
reorganize describes in caip25Permission.test.ts
jiexi Oct 29, 2024
30948a7
Merge branch 'main' into caip-multichain
jiexi Oct 29, 2024
788c9eb
adjust caveat mutator scenarios
jiexi Oct 29, 2024
b859af5
Update packages/multichain/src/adapters/caip-permission-adapter-eth-a…
jiexi Oct 29, 2024
5902e74
Update packages/multichain/src/adapters/caip-permission-adapter-permi…
jiexi Oct 29, 2024
8c10fc0
Update packages/multichain/src/adapters/caip-permission-adapter-permi…
jiexi Oct 29, 2024
7712d54
nest noramlizeScope 'scopeString is chain scoped'
jiexi Oct 29, 2024
1d4a076
Merge remote-tracking branch 'origin/caip-multichain' into caip-multi…
jiexi Oct 29, 2024
d3fbaa9
make Scope Transform normalizeScope chain scoped test body more explicit
jiexi Oct 29, 2024
02f35f5
replace type cast with @ts-expect-error
jiexi Oct 29, 2024
053b5ea
yarn
jiexi Oct 29, 2024
ac9835c
Flatten isValidScope test
jiexi Oct 29, 2024
72e228e
Fix validation.test.ts ts-expect-error
jiexi Oct 29, 2024
bd10406
flatten isSupportedAccount it.each
jiexi Oct 29, 2024
e5e39eb
cleanup removeAccount function docs/comments
adonesky1 Nov 7, 2024
27e0808
add JSDoc for caip25EndowmentBuilder
adonesky1 Nov 7, 2024
0c679a8
repace reduceKeyHelper with Object.fromEntries
adonesky1 Nov 7, 2024
c5ed91c
add bip122 entries to "known" method consts
adonesky1 Nov 7, 2024
91e426c
removeAccountOnScope -> removeAccountFromScopeObject
adonesky1 Nov 7, 2024
619e34d
rename param of 'removeAccount' caip25Permission helper function
adonesky1 Nov 7, 2024
35a81ce
remove unnecessary type assertion
adonesky1 Nov 7, 2024
b04a941
fix bug in normalizeScope
adonesky1 Nov 7, 2024
41e0413
refactor normalizeScope for clarity
adonesky1 Nov 7, 2024
3f56531
add JSDocs for scope(s)Object types
adonesky1 Nov 7, 2024
9c40d69
add JSDocs for Scope types
adonesky1 Nov 7, 2024
71f254a
add 'Internal' prefix to CAIP-25 Scope types
adonesky1 Nov 7, 2024
828080f
improve JSDoc
adonesky1 Nov 7, 2024
de7ac07
Update packages/multichain/src/scope/authorization.ts
adonesky1 Nov 7, 2024
aa24e96
cleanup consts/types and comments
adonesky1 Nov 7, 2024
da87d65
fix imports
adonesky1 Nov 7, 2024
be5a235
Merge branch 'main' into caip-multichain
adonesky1 Nov 7, 2024
8194afd
add more TSDocs
adonesky1 Nov 7, 2024
20311d3
update lock file
adonesky1 Nov 7, 2024
6e345cf
add more documentation + function annotations
adonesky1 Nov 8, 2024
ef5d500
align package versions
adonesky1 Nov 8, 2024
71b9820
update lockfile
adonesky1 Nov 8, 2024
f37586d
add error constants
adonesky1 Nov 8, 2024
67bd1d2
Update packages/multichain/src/scope/constants.ts
adonesky1 Nov 8, 2024
cc686bc
add snapshot test for KnownRpcMethods
adonesky1 Nov 8, 2024
664069b
improve ScopeObject validation
adonesky1 Nov 8, 2024
1abd454
error builder methods
adonesky1 Nov 8, 2024
0899f26
lint
adonesky1 Nov 8, 2024
b99b78f
improve type checks in supported helper methods
adonesky1 Nov 8, 2024
97c59e8
lint
adonesky1 Nov 8, 2024
b700e4f
validateScopes -> getValidScopes
adonesky1 Nov 8, 2024
e576295
narrow validation of references property
adonesky1 Nov 8, 2024
ba9c728
fixup type check functions
adonesky1 Nov 8, 2024
ee616de
add tests for errors file
adonesky1 Nov 8, 2024
5633bdd
add TSDoc
adonesky1 Nov 8, 2024
43cddcc
Update packages/multichain/src/scope/transform.ts
adonesky1 Nov 8, 2024
693ee5c
chore: Suggestion on simplifying type guard (#4912)
Gudahtt Nov 8, 2024
4b1b1b9
lint
adonesky1 Nov 8, 2024
7ceab94
add more tests for transform helpers
adonesky1 Nov 11, 2024
86450dc
add caip25 error code snapshot tests
adonesky1 Nov 11, 2024
858f764
add mocking to fix test
adonesky1 Nov 11, 2024
b525790
fix typo
adonesky1 Nov 11, 2024
6c313bc
Update packages/multichain/src/adapters/caip-permission-adapter-eth-a…
adonesky1 Nov 11, 2024
1a59b95
add getEthAccounts tests
adonesky1 Nov 11, 2024
d73f644
cleanup type casting
adonesky1 Nov 11, 2024
5371ff0
Expand setEthAccounts TSDoc comment
adonesky1 Nov 12, 2024
8d490f7
fix type casting
adonesky1 Nov 12, 2024
aba8857
update TSDoc for addPermittedEthChainId
adonesky1 Nov 12, 2024
fc71fc6
update setPermittedEthChainIds TSDoc
adonesky1 Nov 12, 2024
f7444b2
Update packages/multichain/src/index.ts
adonesky1 Nov 12, 2024
da672b9
Update packages/multichain/src/caip25Permission.ts
adonesky1 Nov 12, 2024
76a0afd
Update packages/multichain/src/caip25Permission.ts
adonesky1 Nov 12, 2024
d10f7d0
improve caip25permission caveat type validation
adonesky1 Nov 12, 2024
e5096d7
Update packages/multichain/src/caip25Permission.ts
adonesky1 Nov 12, 2024
e39e025
Merge branch 'main' into caip-multichain
adonesky1 Nov 12, 2024
f93eb36
update lock file
adonesky1 Nov 12, 2024
5b08f70
fix constraints
adonesky1 Nov 12, 2024
6557b46
update lockfile again
adonesky1 Nov 12, 2024
161dad9
fix tests
adonesky1 Nov 13, 2024
7b3e149
add tests for caip25permission caveat type validation
adonesky1 Nov 13, 2024
a532409
fix Hex type casting
adonesky1 Nov 13, 2024
6c38448
remove redundant addition of wallet:eip155 optional scope
adonesky1 Nov 13, 2024
bce9360
added to setEthAccounts TSDoc to explain why we inject a wallet:eip15…
adonesky1 Nov 13, 2024
f905350
add type/const docs
adonesky1 Nov 13, 2024
d0865d4
lint
adonesky1 Nov 13, 2024
30e6842
Merge branch 'main' into caip-multichain
adonesky1 Nov 13, 2024
555383c
Update packages/multichain/src/index.ts
adonesky1 Nov 13, 2024
bc21a36
update snapshot
adonesky1 Nov 13, 2024
fa20bc0
Merge branch 'main' into caip-multichain
adonesky1 Nov 13, 2024
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
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,9 @@ linkStyle default opacity:0.5
logging_controller --> controller_utils;
message_manager --> base_controller;
message_manager --> controller_utils;
multichain --> controller_utils;
multichain --> network_controller;
multichain --> permission_controller;
name_controller --> base_controller;
name_controller --> controller_utils;
network_controller --> base_controller;
Expand Down
14 changes: 14 additions & 0 deletions packages/multichain/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,18 @@
"test:verbose": "NODE_OPTIONS=--experimental-vm-modules jest --verbose",
"test:watch": "NODE_OPTIONS=--experimental-vm-modules jest --watch"
},
"dependencies": {
"@metamask/api-specs": "^0.10.12",
"@metamask/controller-utils": "^11.4.3",
"@metamask/eth-json-rpc-filters": "^7.0.0",
"@metamask/rpc-errors": "^7.0.1",
"@metamask/utils": "^10.0.0",
"lodash": "^4.17.21"
},
"devDependencies": {
"@metamask/auto-changelog": "^3.4.4",
"@metamask/network-controller": "^22.0.2",
"@metamask/permission-controller": "^11.0.3",
"@types/jest": "^27.4.1",
"deepmerge": "^4.2.2",
"jest": "^27.5.1",
Expand All @@ -56,6 +66,10 @@
"typedoc-plugin-missing-exports": "^2.0.0",
"typescript": "~5.2.2"
},
"peerDependencies": {
"@metamask/network-controller": "^22.0.0",
"@metamask/permission-controller": "^11.0.0"
},
"engines": {
"node": "^18.18 || >=20"
},
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,263 @@
import type { Caip25CaveatValue } from '../caip25Permission';
import {
getEthAccounts,
setEthAccounts,
} from './caip-permission-adapter-eth-accounts';

describe('CAIP-25 eth_accounts adapters', () => {
describe('getEthAccounts', () => {
Gudahtt marked this conversation as resolved.
Show resolved Hide resolved
it('returns an empty array if the required scopes are empty', () => {
const ethAccounts = getEthAccounts({
requiredScopes: {},
optionalScopes: {},
});
expect(ethAccounts).toStrictEqual([]);
});
it('returns an empty array if the scope objects have no accounts', () => {
const ethAccounts = getEthAccounts({
requiredScopes: {
'eip155:1': { methods: [], notifications: [], accounts: [] },
'eip155:2': { methods: [], notifications: [], accounts: [] },
},
optionalScopes: {},
});
expect(ethAccounts).toStrictEqual([]);
});
it('returns an empty array if the scope objects have no eth accounts', () => {
const ethAccounts = getEthAccounts({
requiredScopes: {
'bip122:000000000019d6689c085ae165831e93': {
methods: [],
notifications: [],
accounts: [
'bip122:000000000019d6689c085ae165831e93:128Lkh3S7CkDTBZ8W7BbpsN3YYizJMp8p6',
],
},
},
optionalScopes: {},
});
expect(ethAccounts).toStrictEqual([]);
});

it('returns the unique set of EIP155 accounts from the CAIP-25 caveat value', () => {
const ethAccounts = getEthAccounts({
requiredScopes: {
'eip155:1': {
methods: [],
notifications: [],
accounts: ['eip155:1:0x1', 'eip155:1:0x2'],
},
'eip155:5': {
methods: [],
notifications: [],
accounts: ['eip155:5:0x2', 'eip155:1:0x3'],
},
'bip122:000000000019d6689c085ae165831e93': {
methods: [],
notifications: [],
accounts: [
'bip122:000000000019d6689c085ae165831e93:128Lkh3S7CkDTBZ8W7BbpsN3YYizJMp8p6',
],
},
},
optionalScopes: {
'eip155:1': {
methods: [],
notifications: [],
accounts: ['eip155:1:0x1', 'eip155:1:0x4'],
},
'eip155:10': {
methods: [],
notifications: [],
accounts: [],
},
'eip155:100': {
methods: [],
notifications: [],
accounts: ['eip155:100:0x100'],
},
'wallet:eip155': {
methods: [],
notifications: [],
accounts: ['wallet:eip155:0x5'],
},
},
});

expect(ethAccounts).toStrictEqual([
'0x1',
'0x2',
'0x4',
'0x3',
'0x100',
'0x5',
]);
});
});

describe('setEthAccounts', () => {
it('returns a CAIP-25 caveat value with all EIP-155 scopeObject.accounts set to CAIP-10 account addresses formed from the accounts param', () => {
jiexi marked this conversation as resolved.
Show resolved Hide resolved
const input: Caip25CaveatValue = {
requiredScopes: {
'eip155:1': {
methods: [],
notifications: [],
accounts: ['eip155:1:0x1', 'eip155:1:0x2'],
},
'eip155:5': {
methods: [],
notifications: [],
accounts: ['eip155:5:0x2', 'eip155:1:0x3'],
},
'bip122:000000000019d6689c085ae165831e93': {
methods: [],
notifications: [],
accounts: [
'bip122:000000000019d6689c085ae165831e93:128Lkh3S7CkDTBZ8W7BbpsN3YYizJMp8p6',
],
},
},
optionalScopes: {
'eip155:1': {
methods: [],
notifications: [],
accounts: ['eip155:1:0x1', 'eip155:1:0x4'],
},
'eip155:10': {
methods: [],
notifications: [],
accounts: [],
},
'eip155:100': {
methods: [],
notifications: [],
accounts: ['eip155:100:0x100'],
},
'wallet:eip155': {
methods: [],
notifications: [],
accounts: [],
},
wallet: {
methods: [],
notifications: [],
accounts: [],
},
},
isMultichainOrigin: false,
};

const result = setEthAccounts(input, ['0x1', '0x2', '0x3']);
expect(result).toStrictEqual({
requiredScopes: {
'eip155:1': {
methods: [],
notifications: [],
accounts: ['eip155:1:0x1', 'eip155:1:0x2', 'eip155:1:0x3'],
},
'eip155:5': {
methods: [],
notifications: [],
accounts: ['eip155:5:0x1', 'eip155:5:0x2', 'eip155:5:0x3'],
},
'bip122:000000000019d6689c085ae165831e93': {
methods: [],
notifications: [],
accounts: [
'bip122:000000000019d6689c085ae165831e93:128Lkh3S7CkDTBZ8W7BbpsN3YYizJMp8p6',
],
},
},
optionalScopes: {
'eip155:1': {
methods: [],
notifications: [],
accounts: ['eip155:1:0x1', 'eip155:1:0x2', 'eip155:1:0x3'],
},
'eip155:10': {
methods: [],
notifications: [],
accounts: ['eip155:10:0x1', 'eip155:10:0x2', 'eip155:10:0x3'],
},
'eip155:100': {
methods: [],
notifications: [],
accounts: ['eip155:100:0x1', 'eip155:100:0x2', 'eip155:100:0x3'],
},
'wallet:eip155': {
methods: [],
notifications: [],
accounts: [
'wallet:eip155:0x1',
'wallet:eip155:0x2',
'wallet:eip155:0x3',
],
},
wallet: {
methods: [],
notifications: [],
accounts: [
'wallet:eip155:0x1',
'wallet:eip155:0x2',
'wallet:eip155:0x3',
],
},
},
isMultichainOrigin: false,
});
});

it('returns a CAIP-25 caveat value with missing "wallet:eip155" optional scope filled in, forming CAIP-10 account addresses from the accounts param', () => {
const input: Caip25CaveatValue = {
requiredScopes: {},
optionalScopes: {},
isMultichainOrigin: false,
};

const result = setEthAccounts(input, ['0x1', '0x2', '0x3']);
expect(result).toStrictEqual({
requiredScopes: {},
optionalScopes: {
'wallet:eip155': {
methods: [],
notifications: [],
accounts: [
'wallet:eip155:0x1',
'wallet:eip155:0x2',
'wallet:eip155:0x3',
],
},
},
isMultichainOrigin: false,
});
});

it('does not modify the input CAIP-25 caveat value object in place', () => {
const input: Caip25CaveatValue = {
requiredScopes: {
'eip155:1': {
methods: [],
notifications: [],
accounts: [],
},
},
optionalScopes: {},
isMultichainOrigin: false,
};

const result = setEthAccounts(input, ['0x1', '0x2', '0x3']);
expect(input).toStrictEqual({
requiredScopes: {
'eip155:1': {
methods: [],
notifications: [],
accounts: [],
},
},
optionalScopes: {},
isMultichainOrigin: false,
});
expect(input).not.toStrictEqual(result);
});
});
});
Loading
Loading