-
-
Notifications
You must be signed in to change notification settings - Fork 249
feat: Add CAIP-25 permission and adapters to @metamask/multichain
#4784
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
Merged
Merged
Changes from 167 commits
Commits
Show all changes
169 commits
Select commit
Hold shift + click to select a range
bc56104
Initial package
jiexi a4b52ad
Fix caip25Permission
jiexi 86ab58a
scopes
jiexi 186d4b3
Fix middlewares
jiexi 6a93d1d
Fix adapters except permission middleware
jiexi 231bcaa
Rename handlers js to ts
jiexi 4e52fc0
permission middleware test js ts rename
jiexi 151eaac
fix: typescript + linting (#4788)
shanejonas 85a723e
Added exports for multichain package (#4789)
shanejonas a0bb278
Add requires
jiexi 1cd8ef2
add permittedChains adapter to exports
jiexi c636def
kill scope index barrel
jiexi a6aa7c1
barrel
jiexi 42134f7
Merge branch 'main' into caip-multichain
jiexi a13b9c7
remove subjectTypes from CAIP-25 permission
jiexi 81db877
update eth accounts adapter with empty wallet and wallet:eip155 Scope…
jiexi a3fc263
fix caip25permission spec
jiexi afe5cb9
upsert empty wallet:eip155 when setting permittedChains
jiexi 9ea78be
lint
jiexi 5650d31
Rename scope.test.ts to types.test.ts
jiexi df5167e
add networkClientId type to permission-adapter-middleware
jiexi 9446b0b
fix snapshot
jiexi f65ca24
Merge branch 'main' into caip-multichain
jiexi 941849d
add KnownWalletScopeString enum
jiexi a250de2
stop upserting wallet scope in setEthAccounts()
jiexi aa7ba39
lint
jiexi 8415be6
update removeScope mutator to not revoke permission if requiredScope …
jiexi c7f510e
Fix specificationBuilder jsdoc and typing
jiexi 4afa8f8
Fix caip25permission type
jiexi 597e837
Fix caip25permission type
jiexi 1872188
small dry todo fix
adonesky1 c5d8005
another small dry
adonesky1 54f7c49
Added handler wrappers to better integrate with existing middleware (…
shanejonas ada451d
change subscriptionManager require to import
jiexi 2322e39
lint
jiexi 9b21677
Merge branch 'main' into caip-multichain
jiexi 00a41cb
Jl/caip multichain/update scope object account types (#4803)
jiexi f30dd8b
update @metamask/rpc-errors version
adonesky1 71085a0
fix merge
adonesky1 f2be8f0
Merge branch 'main' into caip-multichain
jiexi 644f4d0
Add isEqualCaseInsensitive to controller-utils
jiexi 1b78bbc
create initial multichain package
jiexi fc28c89
remove API related logic
jiexi ba25ce5
Merge branch 'initialize-caip-multichain' into caip-multichain
jiexi 4ceb118
remove api related deps
jiexi 9bcf869
Fix package.json
jiexi 633485c
Merge branch 'initialize-caip-multichain' into caip-multichain
jiexi afb2e2c
fix bad merge
jiexi 109a7bf
Update packages/controller-utils/src/util.test.ts
jiexi 1e67641
Merge branch 'controller-utils-isEqualCaseInsensitive' into initializ…
jiexi 32b213a
Merge branch 'initialize-caip-multichain' into caip-multichain
jiexi dae4f73
add account support check in validator (#4816)
jiexi d7ed999
Merge branch 'main' into initialize-caip-multichain
jiexi b4b65e2
Merge branch 'initialize-caip-multichain' into caip-multichain
jiexi fad338d
remove caip-permission-adapter-middleware
jiexi c5980c6
remove caip-permission-adapter-middleware from exports
jiexi a7a8e6e
remove types/@metamask/eth-json-rpc-filters.d.ts
jiexi 6b367f0
Merge branch 'main' into caip-multichain
adonesky1 42297f9
add back readme content
adonesky1 26acfcd
Merge branch 'main' into initialize-caip-multichain
jiexi 2e3bfb4
Merge branch 'initialize-caip-multichain' into caip-multichain
jiexi 7203358
bump network-controller dep
jiexi 046133a
add Scoped Properties to Caip25Authorization type
jiexi eea9f46
Merge branch 'main' into caip-multichain
jiexi 67b222e
Fix ScopedProperties type
jiexi 009fb4a
Loosen get adapter param types (#4835)
jiexi 0631c48
Seperate types and constants
jiexi 4685547
Merge branch 'main' into caip-multichain
jiexi 18d1112
remove jest.resetAllMocks
jiexi 1ba77c7
yarn lock
jiexi bb50a19
yarn
jiexi 7d32a0b
100% coverage
jiexi f095370
Remove accountsChanged and chainChanged from KnownNotifications (sinc…
jiexi 62929a4
Merge branch 'main' into caip-multichain
jiexi 491552f
Update packages/multichain/src/scope/transform.test.ts
jiexi bd0f50f
Merge branch 'main' into caip-multichain
jiexi cad5e3e
Merge branch 'main' into caip-multichain
jiexi 757b177
align deps
jiexi dcb593b
rename Caip25CaveatFactoryFn to createCaip25Caveat
jiexi 16aa686
switch removeScope param order
jiexi f8b887c
switch removeAccount param order
jiexi 632db4b
do not export removeScope directly. fix Caip25CaveatMutatorFactories …
jiexi 628a38c
reorder removeAccountOnScope params
jiexi 6346955
rename Caip25CaveatMutatorFactories to Caip25CaveatMutators
jiexi d40d63d
fix barrel export
jiexi d75d5d6
replace node assert with lodash.isEqual
jiexi 23d10ed
reorganize describes in caip25Permission.test.ts
jiexi 30948a7
Merge branch 'main' into caip-multichain
jiexi 788c9eb
adjust caveat mutator scenarios
jiexi b859af5
Update packages/multichain/src/adapters/caip-permission-adapter-eth-a…
jiexi 5902e74
Update packages/multichain/src/adapters/caip-permission-adapter-permi…
jiexi 8c10fc0
Update packages/multichain/src/adapters/caip-permission-adapter-permi…
jiexi 7712d54
nest noramlizeScope 'scopeString is chain scoped'
jiexi 1d4a076
Merge remote-tracking branch 'origin/caip-multichain' into caip-multi…
jiexi d3fbaa9
make Scope Transform normalizeScope chain scoped test body more explicit
jiexi 02f35f5
replace type cast with @ts-expect-error
jiexi 053b5ea
yarn
jiexi ac9835c
Flatten isValidScope test
jiexi 72e228e
Fix validation.test.ts ts-expect-error
jiexi bd10406
flatten isSupportedAccount it.each
jiexi e5e39eb
cleanup removeAccount function docs/comments
adonesky1 27e0808
add JSDoc for caip25EndowmentBuilder
adonesky1 0c679a8
repace reduceKeyHelper with Object.fromEntries
adonesky1 c5ed91c
add bip122 entries to "known" method consts
adonesky1 91e426c
removeAccountOnScope -> removeAccountFromScopeObject
adonesky1 619e34d
rename param of 'removeAccount' caip25Permission helper function
adonesky1 35a81ce
remove unnecessary type assertion
adonesky1 b04a941
fix bug in normalizeScope
adonesky1 41e0413
refactor normalizeScope for clarity
adonesky1 3f56531
add JSDocs for scope(s)Object types
adonesky1 9c40d69
add JSDocs for Scope types
adonesky1 71f254a
add 'Internal' prefix to CAIP-25 Scope types
adonesky1 828080f
improve JSDoc
adonesky1 de7ac07
Update packages/multichain/src/scope/authorization.ts
adonesky1 aa24e96
cleanup consts/types and comments
adonesky1 da87d65
fix imports
adonesky1 be5a235
Merge branch 'main' into caip-multichain
adonesky1 8194afd
add more TSDocs
adonesky1 20311d3
update lock file
adonesky1 6e345cf
add more documentation + function annotations
adonesky1 ef5d500
align package versions
adonesky1 71b9820
update lockfile
adonesky1 f37586d
add error constants
adonesky1 67bd1d2
Update packages/multichain/src/scope/constants.ts
adonesky1 cc686bc
add snapshot test for KnownRpcMethods
adonesky1 664069b
improve ScopeObject validation
adonesky1 1abd454
error builder methods
adonesky1 0899f26
lint
adonesky1 b99b78f
improve type checks in supported helper methods
adonesky1 97c59e8
lint
adonesky1 b700e4f
validateScopes -> getValidScopes
adonesky1 e576295
narrow validation of references property
adonesky1 ba9c728
fixup type check functions
adonesky1 ee616de
add tests for errors file
adonesky1 5633bdd
add TSDoc
adonesky1 43cddcc
Update packages/multichain/src/scope/transform.ts
adonesky1 693ee5c
chore: Suggestion on simplifying type guard (#4912)
Gudahtt 4b1b1b9
lint
adonesky1 7ceab94
add more tests for transform helpers
adonesky1 86450dc
add caip25 error code snapshot tests
adonesky1 858f764
add mocking to fix test
adonesky1 b525790
fix typo
adonesky1 6c313bc
Update packages/multichain/src/adapters/caip-permission-adapter-eth-a…
adonesky1 1a59b95
add getEthAccounts tests
adonesky1 d73f644
cleanup type casting
adonesky1 5371ff0
Expand setEthAccounts TSDoc comment
adonesky1 8d490f7
fix type casting
adonesky1 aba8857
update TSDoc for addPermittedEthChainId
adonesky1 fc71fc6
update setPermittedEthChainIds TSDoc
adonesky1 f7444b2
Update packages/multichain/src/index.ts
adonesky1 da672b9
Update packages/multichain/src/caip25Permission.ts
adonesky1 76a0afd
Update packages/multichain/src/caip25Permission.ts
adonesky1 d10f7d0
improve caip25permission caveat type validation
adonesky1 e5096d7
Update packages/multichain/src/caip25Permission.ts
adonesky1 e39e025
Merge branch 'main' into caip-multichain
adonesky1 f93eb36
update lock file
adonesky1 5b08f70
fix constraints
adonesky1 6557b46
update lockfile again
adonesky1 161dad9
fix tests
adonesky1 7b3e149
add tests for caip25permission caveat type validation
adonesky1 a532409
fix Hex type casting
adonesky1 6c38448
remove redundant addition of wallet:eip155 optional scope
adonesky1 bce9360
added to setEthAccounts TSDoc to explain why we inject a wallet:eip15…
adonesky1 f905350
add type/const docs
adonesky1 d0865d4
lint
adonesky1 30e6842
Merge branch 'main' into caip-multichain
adonesky1 555383c
Update packages/multichain/src/index.ts
adonesky1 bc21a36
update snapshot
adonesky1 fa20bc0
Merge branch 'main' into caip-multichain
adonesky1 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
263 changes: 263 additions & 0 deletions
263
packages/multichain/src/adapters/caip-permission-adapter-eth-accounts.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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', () => { | ||
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); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.