-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Contract refactoring, API, README, etc (#706)
* fix contract tests, add attached and required to errors * error and error messages naming * return more specific errors in user facing functions * fix error conversion issue * separate user facing functions into one impl block * move some of the contract structs to primitives * API and envs README * revert MpcError -> SignError * fmt * Update chain-signatures/contract/src/errors.rs Co-authored-by: DavidM-D <[email protected]> * Update chain-signatures/contract/src/errors.rs Co-authored-by: DavidM-D <[email protected]> * Update chain-signatures/contract/src/errors.rs Co-authored-by: DavidM-D <[email protected]> * Update chain-signatures/contract/src/errors.rs Co-authored-by: DavidM-D <[email protected]> * ignore RUSTSEC-2024-0357 * make sign_helper private --------- Co-authored-by: DavidM-D <[email protected]>
- Loading branch information
Showing
8 changed files
with
273 additions
and
207 deletions.
There are no files selected for viewing
This file contains 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 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,55 @@ | ||
# Chain Signatures API | ||
|
||
## `sign()` | ||
This is the main function of the contract API. It is used to sign a request with the MPC service. | ||
```rust | ||
pub fn sign(&mut self, request: SignRequest) -> Result<near_sdk::Promise, MpcContractError> | ||
``` | ||
Arguments and return type: | ||
```rust | ||
pub struct SignRequest { | ||
pub payload: [u8; 32], | ||
pub path: String, | ||
pub key_version: u32, | ||
} | ||
|
||
pub struct SignResult { | ||
pub big_r: String, | ||
pub s: String, | ||
} | ||
``` | ||
- `key_version` must be less than or equal to the value at `latest_key_version`. | ||
- `path` is a derivation path for the key that will be used to sign the payload. | ||
- To avoid overloading the network with too many requests, we ask for a small deposit for each signature request. The fee changes based on how busy the network is. | ||
|
||
## `public_key()` | ||
This is the root public key combined from all the public keys of the participants. | ||
```rust | ||
pub fn public_key(&self) -> Result<PublicKey, MpcContractError> | ||
``` | ||
|
||
## `derived_public_key()` | ||
This is the derived public key of the caller given path and predecessor. If the predecessor is not provided, it will be the caller of the contract. | ||
```rust | ||
pub fn derived_public_key( | ||
&self, | ||
path: String, | ||
predecessor: Option<AccountId>, | ||
) -> Result<PublicKey, MpcContractError> | ||
``` | ||
|
||
## `latest_key_version()` | ||
Key versions refer new versions of the root key that we may choose to generate on cohort changes. Older key versions will always work but newer key versions were never held by older signers. Newer key versions may also add new security features, like only existing within a secure enclave. Currently only 0 is a valid key version. | ||
```rust | ||
pub const fn latest_key_version(&self) -> u32 | ||
``` | ||
|
||
For more details check `User contract API` impl block in the [chain-signatures/contracts/src/lib.rs](./chain-signatures/contracts/src/lib.rs) file. | ||
|
||
# Environments | ||
Currently, we have 3 environments: | ||
1. Mainnet: `v1.multichain-mpc.near` // TODO: set when available | ||
2. Testnet: `v2.multichain-mpc.testnet` | ||
3. Dev: `v5.multichain-mpc-dev.testnet` | ||
|
||
Contracts can be changed from v1 to v2, etc. Older contracts should continue functioning. |
This file contains 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.