Skip to content

Commit

Permalink
revert code samples to 2 space indents (#1277)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexandratran authored Apr 19, 2024
1 parent 99c4045 commit 59451c1
Show file tree
Hide file tree
Showing 68 changed files with 3,252 additions and 3,300 deletions.
56 changes: 28 additions & 28 deletions snaps/features/custom-evm-accounts/create-account-snap.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,16 +48,16 @@ Specify the following [permissions](../../how-to/request-permissions.md) in your

```json title="snap.manifest.json"
"initialPermissions": {
"endowment:keyring": {
"allowedOrigins": [
"https://<dapp domain>"
]
},
"endowment:rpc": {
"dapps": true
},
"snap_manageAccounts": {},
"snap_manageState": {}
"endowment:keyring": {
"allowedOrigins": [
"https://<dapp domain>"
]
},
"endowment:rpc": {
"dapps": true
},
"snap_manageAccounts": {},
"snap_manageState": {}
},
```

Expand All @@ -71,7 +71,7 @@ Make sure to [limit the methods exposed to dapps](security.md#limit-the-methods-

```typescript
class MySnapKeyring implements Keyring {
// Implement the required methods here.
// Implement the required methods here.
}
```

Expand All @@ -87,16 +87,16 @@ The following is an example of a `personal_sign` request:

```json
{
"id": "d6e23af6-4bea-48dd-aeb0-7d3c30ea67f9",
"scope": "",
"account": "69438371-bef3-4957-9f91-c3f22c1d75f3",
"request": {
"method": "personal_sign",
"params": [
"0x4578616d706c652060706572736f6e616c5f7369676e60206d657373616765",
"0x5874174dcf1ab6F7Efd8496f4f09404CD1c5bA84"
]
}
"id": "d6e23af6-4bea-48dd-aeb0-7d3c30ea67f9",
"scope": "",
"account": "69438371-bef3-4957-9f91-c3f22c1d75f3",
"request": {
"method": "personal_sign",
"params": [
"0x4578616d706c652060706572736f6e616c5f7369676e60206d657373616765",
"0x5874174dcf1ab6F7Efd8496f4f09404CD1c5bA84"
]
}
}
```

Expand Down Expand Up @@ -139,10 +139,10 @@ For example, when an account is created:

```typescript
try {
emitSnapKeyringEvent(snap, KeyringEvent.AccountCreated, { account });
// Update your Snap's state.
emitSnapKeyringEvent(snap, KeyringEvent.AccountCreated, { account });
// Update your Snap's state.
} catch (error) {
// Handle the error.
// Handle the error.
}
```

Expand All @@ -155,11 +155,11 @@ to MetaMask and your dapp:

```typescript
export const onKeyringRequest: OnKeyringRequestHandler = async ({
origin,
request,
origin,
request,
}) => {
// Add custom logic here.
return handleKeyringRequest(keyring, request);
// Add custom logic here.
return handleKeyringRequest(keyring, request);
};
```

Expand Down
96 changes: 48 additions & 48 deletions snaps/features/custom-evm-accounts/security.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,20 +28,20 @@ For example:

```ts
const account: KeyringAccount = {
id: uuid(),
options: {
privateKey: "0x01234...78", // !!! DO NOT DO THIS !!!
},
address,
methods: [
EthMethod.PersonalSign,
EthMethod.Sign,
EthMethod.SignTransaction,
EthMethod.SignTypedDataV1,
EthMethod.SignTypedDataV3,
EthMethod.SignTypedDataV4,
],
type: EthAccountType.Eoa,
id: uuid(),
options: {
privateKey: "0x01234...78", // !!! DO NOT DO THIS !!!
},
address,
methods: [
EthMethod.PersonalSign,
EthMethod.Sign,
EthMethod.SignTransaction,
EthMethod.SignTypedDataV1,
EthMethod.SignTypedDataV3,
EthMethod.SignTypedDataV4,
],
type: EthAccountType.Eoa,
};
```

Expand All @@ -51,14 +51,14 @@ For example:

```ts
await snap.request({
method: "snap_manageState",
params: {
operation: "update",
newState: {
// Your Snap's state here.
privateKey: "0x01234...78",
},
method: "snap_manageState",
params: {
operation: "update",
newState: {
// Your Snap's state here.
privateKey: "0x01234...78",
},
},
});
```

Expand Down Expand Up @@ -101,16 +101,16 @@ The following is an example of implementing such logic:

```ts
const permissions: Record<string, string[]> = {
"https://<Dapp 1 domain>": [
// List of allowed methods for Dapp 1.
],
"https://<Dapp 2 domain>": [
// List of allowed methods for Dapp 2.
],
"https://<Dapp 1 domain>": [
// List of allowed methods for Dapp 1.
],
"https://<Dapp 2 domain>": [
// List of allowed methods for Dapp 2.
],
};
if (origin !== "metamask" && !permissions[origin]?.includes(request.method)) {
// Reject the request.
// Reject the request.
}
```

Expand All @@ -124,14 +124,14 @@ redirected to a malicious website.

```ts
async submitRequest(request: KeyringRequest): Promise<SubmitRequestResponse> {
// Your Snap's custom logic.
return {
pending: true,
redirect: {
message: "Please continue in the dapp.",
url: "https://<dapp domain>/sign?tx=1234", // !!! ENSURE THIS IS A SAFE URL !!!
},
};
// Your Snap's custom logic.
return {
pending: true,
redirect: {
message: "Please continue in the dapp.",
url: "https://<dapp domain>/sign?tx=1234", // !!! ENSURE THIS IS A SAFE URL !!!
},
};
}
```

Expand Down Expand Up @@ -170,10 +170,10 @@ For example:

```ts
try {
const privateKey = toBuffer(inputSecretValue);
// Use privateKey here.
const privateKey = toBuffer(inputSecretValue);
// Use privateKey here.
} catch (error) {
throw new Error("Invalid private key");
throw new Error("Invalid private key");
}
```

Expand All @@ -190,24 +190,24 @@ For example:

```ts
export const onRpcRequest: OnRpcRequestHandler = async ({
// ~~~ ~~~
origin,
request,
// ~~~ ~~~
origin,
request,
}) => {
return handleKeyringRequest(keyring, request);
return handleKeyringRequest(keyring, request);
};
```

-**Do this instead:**

```ts
export const onKeyringRequest: OnKeyringRequestHandler = async ({
// ~~~~~~~ ~~~~~~~
origin,
request,
// ~~~~~~~ ~~~~~~~
origin,
request,
}) => {
// Any custom logic or extra security checks here.
return handleKeyringRequest(keyring, request);
// Any custom logic or extra security checks here.
return handleKeyringRequest(keyring, request);
};
```

Expand Down
40 changes: 20 additions & 20 deletions snaps/features/custom-name-resolution.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ For example, to resolve Ethereum Mainnet domains, add the following to your Snap

```json title="snap.manifest.json"
"initialPermissions": {
"endowment:name-lookup": {
"chains": ["eip155:1"]
}
"endowment:name-lookup": {
"chains": ["eip155:1"]
}
}
```

Expand All @@ -41,25 +41,25 @@ import type { OnNameLookupHandler } from "@metamask/snaps-types";
const UNSTOPPABLE_API_KEY = "xxx";

export const onNameLookup: OnNameLookupHandler = async (request) => {
const { chainId, domain } = request;

if (domain && chainId === "eip155:1") {
const response = await fetch(`https://api.unstoppabledomains.com/resolve/domains/${domain}`, {
headers: {
accept: "application/json",
authorization: `Bearer ${UNSTOPPABLE_API_KEY}`,
},
});
const data = await response.json();
const resolvedAddress = data.records["crypto.ETH.address"];
if (address) {
return {
resolvedAddresses: [{ resolvedAddress, protocol: "Unstoppable Domains" }],
};
}
const { chainId, domain } = request;

if (domain && chainId === "eip155:1") {
const response = await fetch(`https://api.unstoppabledomains.com/resolve/domains/${domain}`, {
headers: {
accept: "application/json",
authorization: `Bearer ${UNSTOPPABLE_API_KEY}`,
},
});
const data = await response.json();
const resolvedAddress = data.records["crypto.ETH.address"];
if (address) {
return {
resolvedAddresses: [{ resolvedAddress, protocol: "Unstoppable Domains" }],
};
}
}

return null;
return null;
};
```

Expand Down
Loading

0 comments on commit 59451c1

Please sign in to comment.