Skip to content
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

Add code formatting #217

Merged
merged 1 commit into from
Jul 18, 2023
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
6 changes: 3 additions & 3 deletions examples/protocol-kit/index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { ethers } from 'ethers'
import SafeApiKit from '@safe-global/api-kit'
import Safe, { EthersAdapter, SafeFactory, SafeAccountConfig } from '@safe-global/protocol-kit'
import Safe, { EthersAdapter, SafeAccountConfig, SafeFactory } from '@safe-global/protocol-kit'
import { SafeTransaction, SafeTransactionDataPartial } from '@safe-global/safe-core-sdk-types'
import { ethers } from 'ethers'

// Run this file:
// source examples/.env
// Source examples/.env
// npx ts-node examples/protocol-kit/index.ts

// https://chainlist.org/?search=goerli&testnets=true
Expand Down
70 changes: 35 additions & 35 deletions other/eip-1271.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ As Safe{Wallet} is a multi signature wallet, this process can take some time bec

#### Example: sign message

```ts
import { hashMessage, hexlify, toUtf8Bytes } from 'ethers/lib/utils';
```typescript
import { hashMessage, hexlify, toUtf8Bytes } from 'ethers/lib/utils'

const signMessage = async (message: string) => {
const hexMessage = hexlify(toUtf8Bytes(message));
const signature = await connector.signMessage([safeAddress, hexMessage]);
};
const hexMessage = hexlify(toUtf8Bytes(message))
const signature = await connector.signMessage([safeAddress, hexMessage])
}
```

After signing a message it will be available in the Safe's Message list (Transactions -> Messages).
Expand All @@ -48,7 +48,7 @@ As Safe{Wallet} is a multi signature wallet, this process can take some time bec

### Example: sign typed data

```ts
```typescript
const getExampleData = () => {
return {
types: {
Expand All @@ -70,16 +70,16 @@ const getExampleData = () => {
message: {
content: 'Hello World!',
},
};
};
}
}

const signTypedData = async () => {
const typedData = getExampleData();
const typedData = getExampleData()
const signature = await connector.signTypedData([
safeAddress,
JSON.stringify(typedData),
]);
};
])
}
```

After signing, the message will be available in the Safe's Message list (Transactions -> Messages).
Expand All @@ -92,16 +92,16 @@ To do so we have to generate a hash of the `message` or `typedData` using ethers

### Example: get Safe message hash

```ts
```typescript
const getSafeInterface = () => {
const SAFE_ABI = [
'function getThreshold() public view returns (uint256)',
'function getMessageHash(bytes memory message) public view returns (bytes32)',
'function isValidSignature(bytes calldata _data, bytes calldata _signature) public view returns (bytes4)',
];
'function isValidSignature(bytes calldata _data, bytes calldata _signature) public view returns (bytes4)'
]

return new Interface(SAFE_ABI);
};
return new Interface(SAFE_ABI)
}

const getSafeMessageHash = async (
connector: WalletConnect,
Expand All @@ -112,13 +112,13 @@ const getSafeMessageHash = async (
const getMessageHash = getSafeInterface().encodeFunctionData(
'getMessageHash',
[messageHash]
);
)

return connector.sendCustomRequest({
method: 'eth_call',
params: [{ to: safeAddress, data: getMessageHash }],
});
};
params: [{ to: safeAddress, data: getMessageHash }]
})
}
```

Then we can query the state of the message from the network-specific transaction service endpoint for messages: `https://safe-transaction-<Network>.safe.global/api/v1/messages/<SafeMsgHash>`.
Expand All @@ -129,29 +129,29 @@ For other network endpoints, see [Available Services](../../safe-core-api/availa

### Example: Loading message from transaction service

```ts
```typescript
const fetchMessage = async (
safeMessageHash: string
): Promise<TransactionServiceSafeMessage | undefined> => {
const safeMessage = await fetch(
`https://safe-transaction-goerli.safe.global/api/v1/messages/${safeMessageHash}`,
{
headers: { 'Content-Type': 'application/json' },
headers: { 'Content-Type': 'application/json' }
}
).then((res) => {
if (!res.ok) {
return Promise.reject('Invalid response when fetching SafeMessage');
return Promise.reject('Invalid response when fetching SafeMessage')
}
return res.json() as Promise<TransactionServiceSafeMessage>;
});
return res.json() as Promise<TransactionServiceSafeMessage>
})

return safeMessage;
};
return safeMessage
}
```

A Safe message has the following format:

```ts
```typescript
{
"messageHash": string,
"status": string,
Expand Down Expand Up @@ -185,8 +185,8 @@ _Note: A common pitfall is to pass the `safeMessageHash` to the `isValidSignatur

### Example: verify signature

```ts
const MAGIC_VALUE_BYTES = '0x20c13b0b';
```typescript
const MAGIC_VALUE_BYTES = '0x20c13b0b'

const isValidSignature = async (
connector: WalletConnect,
Expand All @@ -198,15 +198,15 @@ const isValidSignature = async (
const isValidSignatureData = getSafeInterface().encodeFunctionData(
'isValidSignature',
[messageHash, signature]
);
)

const isValidSignature = (await connector.sendCustomRequest({
method: 'eth_call',
params: [{ to: safeAddress, data: isValidSignatureData }],
})) as string;
params: [{ to: safeAddress, data: isValidSignatureData }]
})) as string

return isValidSignature?.slice(0, 10).toLowerCase() === MAGIC_VALUE_BYTES;
};
return isValidSignature?.slice(0, 10).toLowerCase() === MAGIC_VALUE_BYTES
}
```

### Example dApps
Expand Down
2 changes: 1 addition & 1 deletion reference/safe-core-sdk/auth-kit/AuthKitBasePack.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ This class is used to create new packs. Any new pack should extend this class an

```typescript
class MyPack extends AuthKitBasePack {
// ... Implementing the abstract methods
// Implementation of the abstract methods
}
```

Expand Down
4 changes: 2 additions & 2 deletions reference/safe-core-sdk/auth-kit/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ To use one of our packs, add the corresponding pack required packages:
Start working with one of our packs is as easy as instantiate the main class and and call the common `init()` method afterwards.

```typescript
const pack = new Web3AuthModalPack(packConfig);
await pack.init(packInitOptions);
const pack = new Web3AuthModalPack(packConfig)
await pack.init(packInitOptions)
```

After the initialization, you can use the pack methods to interact with the chosen provider. There are some common methods (`signIn()`, `signOut()`, etc.) that you can use with any pack. It creates a common interface that any pack should implement. Check the abstract class [`AuthKitBasePack`](./AuthKitBasePack.md) for more information.
Expand Down
24 changes: 12 additions & 12 deletions reference/safe-core-sdk/auth-kit/Web3AuthModalPack.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ The `Web3AuthModalPack` class is what makes Web3Auth modal and Safe work togethe

```typescript
const web3AuthModalPack = new Web3AuthModalPack({
txServiceUrl: 'https://safe-transaction-mainnet.safe.global',
});
await web3AuthModalPack.init(web3AuthModalOptions, [adapters], modalConfig);
txServiceUrl: 'https://safe-transaction-mainnet.safe.global'
})
await web3AuthModalPack.init(web3AuthModalOptions, [adapters], modalConfig)
```


Expand All @@ -40,7 +40,7 @@ await web3AuthModalPack.init(web3AuthModalOptions, [adapters], modalConfig);

```typescript
Web3AuthConfig {
txServiceUrl: string;
txServiceUrl: string
}
```
- `txServiceUrl` - The URL of the Safe transaction service. It is used to retrieve the Safe addresses for an external owned account created using Web3Auth services. It is required to use the `Web3AuthModalPack` with Safe.
Expand Down Expand Up @@ -135,18 +135,18 @@ Calling `init()` when your page loads or component renders is all it takes to us
```typescript
// Instantiate and initialize the pack
const web3AuthModalPack = new Web3AuthModalPack(web3AuthConfig)
await web3AuthModalPack.init(web3AuthModalOptions, adapters, modalConfig);
await web3AuthModalPack.init(web3AuthModalOptions, adapters, modalConfig)

// Sign in
const { eoa, safes } = await web3AuthModalPack.signIn();
const userInfo = await web3AuthModalPack.getUserInfo();
const web3Provider = web3AuthModalPack.getProvider();
const { eoa, safes } = await web3AuthModalPack.signIn()
const userInfo = await web3AuthModalPack.getUserInfo()
const web3Provider = web3AuthModalPack.getProvider()

// Subscribe to events
const handler = (event) => {};
web3AuthModalPack.subscribe(packEvent, handler);
web3AuthModalPack.unsubscribe(packEvent, handler);
const handler = (event) => {}
web3AuthModalPack.subscribe(packEvent, handler)
web3AuthModalPack.unsubscribe(packEvent, handler)

// Sign out
await web3AuthModalPack.signOut();
await web3AuthModalPack.signOut()
```
22 changes: 11 additions & 11 deletions reference/safe-core-sdk/onramp-kit/MoneriumPack.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ This pack allows you to "Login with Monerium" by creating a connection between y
const moneriumPack = new MoneriumPack({
clientId: 'YOUR_CLIENT_ID',
environment: 'sandbox'
});
await moneriumPack.init(moneriumInitOptions);
})
await moneriumPack.init(moneriumInitOptions)
```

#### `new MoneriumPack(moneriumConfig)`
Expand Down Expand Up @@ -130,10 +130,10 @@ You can subscribe to [order status changes](https://monerium.dev/api-docs#operat

```typescript
MoneriumEvent {
placed = "placed",
pending = "pending",
processed = "processed",
rejected = "rejected"
placed = 'placed',
pending = 'pending',
processed = 'processed',
rejected = 'rejected'
}
```

Expand Down Expand Up @@ -164,13 +164,13 @@ const moneriumPack = new MoneriumPack(moneriumConfig)
moneriumPack.init({ safeSdk })

// Open
const safeMoneriumClient = await moneriumPack.open(moneriumPackOpenOptions);
const safeMoneriumClient = await moneriumPack.open(moneriumPackOpenOptions)

// Subscribe to events
const handler = (event) => {};
moneriumPack.subscribe(MoneriumEvent.placed, handler);
moneriumPack.unsubscribe(MoneriumEvent.processed, handler);
const handler = (event) => {}
moneriumPack.subscribe(MoneriumEvent.placed, handler)
moneriumPack.unsubscribe(MoneriumEvent.processed, handler)

// Close
await moneriumPack.close();
await moneriumPack.close()
```
2 changes: 1 addition & 1 deletion reference/safe-core-sdk/onramp-kit/OnRampKitBasePack.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ This class is used to create new packs. Any new pack should extend this class an

```typescript
class MyPack extends OnRampKitBasePack {
// ... Implementing the abstract methods
// Implementation of the abstract methods
}
```

Expand Down
4 changes: 2 additions & 2 deletions reference/safe-core-sdk/onramp-kit/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ To use one of our developed packs, add the required packages.
To start working with our packs, instantiate the main class and and call the common `init()` method afterwards.

```typescript
const pack = new MoneriumPack(packConfig);
await pack.init(packInitOptions);
const pack = new MoneriumPack(packConfig)
await pack.init(packInitOptions)
```

After the initialization, you can use the pack specific methods to interact with the chosen provider. There are some common methods (`open()`, `close()`, etc.) that you can use with any pack, it's the common interface that any pack should implement. Check the abstract class [`OnRampKitBasePack`](./OnRampKitBasePack.md) for more information.
Expand Down
14 changes: 7 additions & 7 deletions reference/safe-core-sdk/onramp-kit/StripePack.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ The `StripePack` allow you to use the Stripe Crypto OnRamp services with Safe. Y
This pack provides a customizable widget for users to purchase cryptocurrencies using Stripe services. It can be rendered in any chosen CSS selector on a webpage.

```typescript
const stripePack = new StripePack(stripeConfig);
await stripePack.init();
const stripePack = new StripePack(stripeConfig)
await stripePack.init()
```

#### `new StripePack(stripeConfig)`
Expand Down Expand Up @@ -101,13 +101,13 @@ const stripePack = new StripePack(stripeConfig)
stripePack.init()

// Open
await stripePack.open(stripePackOpenOptions);
await stripePack.open(stripePackOpenOptions)

// Subscribe to events
const handler = (event) => {};
stripePack.subscribe('onramp_ui_loaded', handler);
stripePack.unsubscribe('onramp_session_updated', handler);
const handler = (event) => {}
stripePack.subscribe('onramp_ui_loaded', handler)
stripePack.unsubscribe('onramp_session_updated', handler)

// Close
await stripePack.close();
await stripePack.close()
```
4 changes: 2 additions & 2 deletions safe-core-api/rpc-requirements.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@

To run the tx service in **tracing mode** you will need a tracing compatible node:

* [Erigon ](https://github.com/ledgerwatch/erigon)node (recommended).&#x20;
* [Erigon ](https://github.com/ledgerwatch/erigon)node (recommended).
* Deprecated [OpenEthereum ](https://github.com/openethereum/openethereum)node with tracing enabled (`--tracing` flag) if it's still supported on your network.
* [Nethermind ](https://nethermind.io/)(**archive mode** so tracing is enabled).
* **Any RPC** that supports **eth_getLogs** if using the **Safe L2 Version.** From Safe **v1.3.0** there's an alternative and **recommended way** to avoid using tracing, the **L2 Safe version** ([https://github.com/safe-global/safe-deployments/blob/main/src/assets/v1.3.0/gnosis_safe_l2.json](https://github.com/safe-global/safe-deployments/blob/main/src/assets/v1.3.0/gnosis_safe_l2.json)) that emits events, so no tracing node is required. This is the approach used in networks like _Polygon_ or _Binance Smart Chain_ where fees are cheap and emitting events don't impact the user:
* A tx service configured **with a tracing** node can index L2 and non L2 versions of the Safe contracts.&#x20;
* A tx service configured **with a tracing** node can index L2 and non L2 versions of the Safe contracts.
* A tx service configured **without a tracing** node can only index L2 versions of the Safe contracts. Indexing mode should not be changed after initializing the service, as the database could become corrupted, so if a tracing node was not set up it shouldn't be added later. The opposite is also problematic.

### What RPC methods are used? <a href="#what-rpc-methods-are-used" id="what-rpc-methods-are-used"></a>
Expand Down
2 changes: 1 addition & 1 deletion safe-core-protocol/modules.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Modules add custom features to Safe contracts. They are smart contracts that imp

Modules can include daily spending allowances, amounts that can be spent without the approval of other owners, recurring transactions modules, standing orders that are performed on a recurring set date, e.g. paying your rent, and social recovery modules, which may allow you to recover a Safe if you lose access to owner accounts. These are just a few examples of how to use modules, but there are many other ways you could use modules in your Safe.

<figure><img src="https://user-images.githubusercontent.com/9806858/234940596-321b1c8c-c311-4016-84fe-d8aa8f550b06.jpg" alt=""><figcaption><p>Safe Module Interaction with a Safe Smart Account. Source: <a href="https://safe.mirror.xyz/P83_rVQuUQJAM-SnMpWvsHlN8oLnCeSncD1txyMDqpE">Safe Smart Accounts &#x26; Diamond Proxies</a></p></figcaption></figure>
<figure><img src="https://user-images.githubusercontent.com/9806858/234940596-321b1c8c-c311-4016-84fe-d8aa8f550b06.jpg" alt=""><figcaption><p>Safe Module Interaction with a Safe Smart Account. Source: <a href="https://safe.mirror.xyz/P83_rVQuUQJAM-SnMpWvsHlN8oLnCeSncD1txyMDqpE">Safe Smart Accounts & Diamond Proxies</a></p></figcaption></figure>

## How to Create a Safe Module

Expand Down
6 changes: 3 additions & 3 deletions safe-core-protocol/signatures/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,10 @@ Assuming that three signatures are required to confirm a transaction where one s

We assume that the following addresses generate the following signatures:

1. `0x3` (EOA address) -&gt; `bde0b9f486b1960454e326375d0b1680243e031fd4fb3f070d9a3ef9871ccfd5` (r) + `7d1a653cffb6321f889169f08e548684e005f2b0c3a6c06fba4c4a68f5e00624` (s) + `1c` (v)
2. `0x1` (EIP-1271 validator contract address) -&gt; `0000000000000000000000000000000000000000000000000000000000000001` (address) + `00000000000000000000000000000000000000000000000000000000000000c3` (dynamic position) + `00` (signature type)
1. `0x3` (EOA address) -> `bde0b9f486b1960454e326375d0b1680243e031fd4fb3f070d9a3ef9871ccfd5` (r) + `7d1a653cffb6321f889169f08e548684e005f2b0c3a6c06fba4c4a68f5e00624` (s) + `1c` (v)
2. `0x1` (EIP-1271 validator contract address) -> `0000000000000000000000000000000000000000000000000000000000000001` (address) + `00000000000000000000000000000000000000000000000000000000000000c3` (dynamic position) + `00` (signature type)
* The contract takes the following `bytes` (dynamic part) for verification `00000000000000000000000000000000000000000000000000000000deadbeef`
3. `0x2` (Validator address) -&gt; `0000000000000000000000000000000000000000000000000000000000000002` (address) +`0000000000000000000000000000000000000000000000000000000000000000` (padding - not used) + `01` (signature type)
3. `0x2` (Validator address) -> `0000000000000000000000000000000000000000000000000000000000000002` (address) +`0000000000000000000000000000000000000000000000000000000000000000` (padding - not used) + `01` (signature type)

The constant parts need to be sorted so that the recovered signers are sorted **ascending** (natural order) by address (not checksummed).

Expand Down
Loading