Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
12 changes: 10 additions & 2 deletions packages/snap/snap.manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"url": "https://github.com/MetaMask/snap-stellar-wallet.git"
},
"source": {
"shasum": "1ftcq5ewpbXIRZpVifhbpo4kHtdvXB4MEoo+bgjMWGQ=",
"shasum": "KKCzkWtnRdUUT9Y0h8yBcyM0ZVt9ZQHAjRBpSr921h8=",
"location": {
"npm": {
"filePath": "dist/bundle.js",
Expand All @@ -23,7 +23,15 @@
},
"initialPermissions": {
"endowment:keyring": {
"allowedOrigins": ["https://portfolio.metamask.io"]
"allowedOrigins": ["https://portfolio.metamask.io"],
"capabilities": {
"scopes": ["stellar:pubnet"],
"bip44": {
"deriveIndex": true,
"deriveIndexRange": true,
"discover": true
}
}
},
"snap_getBip32Entropy": [
{
Expand Down
3 changes: 2 additions & 1 deletion packages/snap/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
UrlStruct,
KnownCaip2ChainId,
} from './api';
import { getSupportedScopes } from './utils/scopes';

const DEFAULT_TOKEN_API_BASE_URL = 'https://tokens.api.cx.metamask.io';

Expand Down Expand Up @@ -77,7 +78,7 @@ const networkConfigStruct = object({
* If the selected network is empty, it returns the default selected network.
*/
const selectedNetworkStruct = coerce(
defaulted(KnownCaip2ChainIdStruct, KnownCaip2ChainId.Mainnet),
defaulted(enums(getSupportedScopes()), KnownCaip2ChainId.Mainnet),
string(),
(value: string) => (value === '' ? undefined : value.toLowerCase()),
);
Expand Down
9 changes: 9 additions & 0 deletions packages/snap/src/constants.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
import { XlmAccountType } from '@metamask/keyring-api';

import snapManifest from '../snap.manifest.json';

/**
* Scopes supported by this snap for account creation and discovery. The snap
* manifest's `endowment:keyring` capabilities are the source of truth.
*/
export const SUPPORTED_SCOPES =
snapManifest.initialPermissions['endowment:keyring'].capabilities.scopes;

Comment thread
stanleyyconsensys marked this conversation as resolved.
/**
* The base reserve for the Stellar network.
*
Expand Down
51 changes: 0 additions & 51 deletions packages/snap/src/handlers/keyring/api.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { assert, StructError } from '@metamask/superstruct';
import {
CreateAccountOptionsStruct,
ResolveAccountAddressRequestStruct,
DiscoverAccountsStruct,
ListAccountTransactionsRequestStruct,
MultichainMethod,
MultichainMethodStruct,
Expand Down Expand Up @@ -178,56 +177,6 @@ describe('ResolveAccountAddressRequestStruct', () => {
});
});

describe('DiscoverAccountsStruct', () => {
it('accepts a valid discoverAccounts request', () => {
const request = {
scopes: [KnownCaip2ChainId.Mainnet],
entropySource: 'entropy-source-1',
groupIndex: 0,
};
expect(() => assert(request, DiscoverAccountsStruct)).not.toThrow();
});

it('accepts multiple scopes', () => {
const request = {
scopes: [KnownCaip2ChainId.Mainnet, KnownCaip2ChainId.Testnet],
entropySource: 'entropy-source-1',
groupIndex: 0,
};
expect(() => assert(request, DiscoverAccountsStruct)).not.toThrow();
});

it.each([
{
scopes: [],
entropySource: 'entropy-source-1',
groupIndex: 1,
},
{
scopes: [KnownCaip2ChainId.Mainnet],
entropySource: 'entropy-source-1',
groupIndex: 1.5,
},
{
scopes: [KnownCaip2ChainId.Mainnet],
entropySource: 'entropy-source-1',
groupIndex: -1,
},
{
scopes: [KnownCaip2ChainId.Mainnet],
entropySource: 'entropy-source-1',
groupIndex: '0',
},
{
scopes: 'invalid-chain-id' as KnownCaip2ChainId,
entropySource: 'entropy-source-1',
groupIndex: 0,
},
])('rejects an invalid discoverAccounts request', (request) => {
expect(() => assert(request, DiscoverAccountsStruct)).toThrow(StructError);
});
});

describe('SignMessageRequestStruct', () => {
const validSignMessageRequest = {
id: keyringRequestId,
Expand Down
9 changes: 0 additions & 9 deletions packages/snap/src/handlers/keyring/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,15 +91,6 @@ export const ResolveAccountAddressRequestStruct = object({
scope: KnownCaip2ChainIdStruct,
});

/**
* Validation struct for the discoverAccounts request.
*/
export const DiscoverAccountsStruct = object({
scopes: nonempty(array(KnownCaip2ChainIdStruct)),
entropySource: nonempty(string()),
groupIndex: min(integer(), 0),
});

/**
* Optional bag accepted by both SEP-43 sign methods.
*
Expand Down
22 changes: 0 additions & 22 deletions packages/snap/src/handlers/keyring/exceptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import {
TransactionValidationException,
} from '../../services/transaction/exceptions';
import { HttpException } from '../../utils';
import type { StellarSnapExceptionOptions } from '../../utils/errors';
import { StellarSnapException } from '../../utils/errors';

export class KeyringException extends StellarSnapException {}
Expand Down Expand Up @@ -131,24 +130,3 @@ export function toSep43Error(error: unknown): Sep43Error {

return new Sep43Error({ code: Sep43ErrorCode.Internal });
}

export class KeyringAccountRollbackException extends KeyringException {
constructor(accountId: string, options?: StellarSnapExceptionOptions) {
super(
`Failed to rollback account creation for account ${accountId}`,
options,
);
}
}

export class KeyringEmitAccountCreatedEventException extends KeyringException {
constructor(options?: StellarSnapExceptionOptions) {
super('Failed to emit account created event', options);
}
}

export class KeyringEmitAccountDeletedEventException extends KeyringException {
constructor(options?: StellarSnapExceptionOptions) {
super('Failed to emit account deleted event', options);
}
}
Loading
Loading