Skip to content
Open
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": "G1F+8GcOTJrPQwRXwwjvo/3yN2g0h49P9OnTvyxJm/M=",
"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
11 changes: 11 additions & 0 deletions packages/snap/src/constants.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
import { XlmAccountType } from '@metamask/keyring-api';

import type { KnownCaip2ChainId } from './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 as KnownCaip2ChainId[];

/**
* 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