-
-
Notifications
You must be signed in to change notification settings - Fork 13
feat: adds Tron support #349
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 4 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
98fe259
chore: adds tron
zone-live d94c1e8
chore: clean up
zone-live 0bb29ce
chore: update migrations
zone-live 39cf7a9
chore: lint fix
zone-live 5d78467
chore: lint fix
zone-live 3b43a35
chore: update enum
zone-live a028112
chore: tests update
zone-live 69d1502
chore: regex update
zone-live 219dc93
chore: lint fix
zone-live 0c4984b
chore: adds tron to keyring-internal-api types
zone-live 2580518
chore: clean up
zone-live 13ca13f
chore: lint
zone-live 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
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,10 @@ | ||
| // istanbul ignore file | ||
|
|
||
| /** | ||
| * Scopes for TRON account type. See {@link KeyringAccount.scopes}. | ||
| */ | ||
| export enum TrxScope { | ||
| Mainnet = 'tron:728126428', | ||
| Nile = 'tron:3448148188', | ||
| Shasta = 'tron:2494104990', | ||
| } |
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,2 @@ | ||
| export * from './constants'; | ||
| export * from './types'; |
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,8 @@ | ||
| import type { Extends } from '@metamask/keyring-utils'; | ||
| import { expectTrue } from '@metamask/keyring-utils'; | ||
|
|
||
| import type { TrxEoaAccount } from './types'; | ||
| import type { KeyringAccount } from '../api'; | ||
|
|
||
| // `TrxEoaAccount` extends `KeyringAccount` | ||
| expectTrue<Extends<TrxEoaAccount, KeyringAccount>>(); |
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,28 @@ | ||
| import { TrxAddressStruct } from './types'; | ||
|
|
||
| describe('types', () => { | ||
| describe('TrxAddressStruct', () => { | ||
| it.each([ | ||
| 'TRjE1H8dxypKM1NZRdysbs9wo7huR4bdNz', | ||
| 'TPAe77oEGDLXuNjJhTyYeo5vMqLYdE3GN8U', | ||
| ])('is valid address: %s', (address) => { | ||
| expect(() => TrxAddressStruct.assert(address)).not.toThrow(); | ||
| }); | ||
|
|
||
| it.each([ | ||
| // Invalid lengths, too long (45 chars) | ||
| 'TRjE1H8dxypKM1NZRdysbs9wo7huR4bdNz1', | ||
| // Too short (31 chars) | ||
| 'TRjE1H8dxypKM1NZRdywo7huR4bdNz', | ||
| // Empty or invalid input | ||
| '', | ||
| // Eth style address | ||
| '0x1234', | ||
| 'not-an-address', | ||
| ])('rejects invalid address: %s', (address) => { | ||
| expect(() => TrxAddressStruct.assert(address)).toThrow( | ||
| `Expected a value of type \`TrxAddress\`, but received: \`"${address}"\``, | ||
| ); | ||
| }); | ||
| }); | ||
| }); |
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,49 @@ | ||
| import { object } from '@metamask/keyring-utils'; | ||
| import type { Infer } from '@metamask/superstruct'; | ||
| import { array, enums, literal, nonempty } from '@metamask/superstruct'; | ||
| import { definePattern } from '@metamask/utils'; | ||
|
|
||
| import { | ||
| CaipChainIdStruct, | ||
| KeyringAccountStruct, | ||
| TrxAccountType, | ||
| } from '../api'; | ||
|
|
||
| /** | ||
| * TRON addresses are Base58-encoded strings that are exactly 34 characters long | ||
| * and start with the letter 'T'. | ||
| */ | ||
| export const TrxAddressStruct = definePattern( | ||
| 'TrxAddress', | ||
| /^T[1-9A-HJ-NP-Za-km-z]{33}$/iu, | ||
| ); | ||
|
|
||
| /** | ||
| * Supported TRON methods. | ||
| */ | ||
| export declare enum TrxMethod { | ||
| SignMessageV2 = 'signMessageV2', | ||
| VerifyMessageV2 = 'verifyMessageV2', | ||
| } | ||
|
|
||
| export const TrxEoaAccountStruct = object({ | ||
| ...KeyringAccountStruct.schema, | ||
| /** | ||
| * Account address. | ||
| */ | ||
| address: TrxAddressStruct, | ||
| /** | ||
| * Account type. | ||
| */ | ||
| type: literal(`${TrxAccountType.Eoa}`), | ||
| /** | ||
| * Account supported scopes (CAIP-2 chain IDs). | ||
| */ | ||
| scopes: nonempty(array(CaipChainIdStruct)), | ||
| /** | ||
| * Account supported methods. | ||
| */ | ||
| methods: array(enums(Object.values(TrxMethod))), | ||
| }); | ||
|
|
||
| export type TrxEoaAccount = Infer<typeof TrxEoaAccountStruct>; | ||
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
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.