-
Notifications
You must be signed in to change notification settings - Fork 19
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
A doc with examples of commands #913
Merged
+327
−2
Merged
Changes from 9 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
f7c6258
build three commands
6909650
updated docs and passed all example commands
7c1b372
wronge testnet id and path
e73514b
Merge remote-tracking branch 'origin/develop' into command-builder
6579b2b
Merge remote-tracking branch 'origin/develop' into command-builder
65383e3
error handling
2a670fa
Merge remote-tracking branch 'origin/develop' into command-builder
b92d0a0
Merge branch 'develop' into command-builder
AlexKushnir1 0f67fee
Merge remote-tracking branch 'origin/develop' into command-builder
98ffa23
Merge branch 'near:develop' into command-builder
AlexKushnir1 29e50bb
Shorter about near-cli
AlexKushnir1 ad86225
Naming
AlexKushnir1 67487d5
Change caller id
AlexKushnir1 d55e1de
pass correct testnet contract id
91b62be
Merge branch 'command-builder' of github.com:AlexKushnir1/mpc into co…
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,49 @@ | ||
# Iteracting with contract using NEAR CLI | ||
All data is fake and used for example purposes | ||
It's necessary to update script after contract API changes | ||
## User contract API | ||
|
||
near call v1.signer-dev.testnet sign '{"request":{"key_version":0,"path":"test","payload":[12,1,2,0,4,5,6,8,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,44]}}' --accountId alexkushnir.testnet --gas 300000000000000 --deposit 1 | ||
|
||
near view v1.signer-dev.testnet public_key | ||
|
||
near view v1.signer-dev.testnet derived_public_key {"path":"test","predecessor":"alexkushnir.testnet"} | ||
|
||
near view v1.signer-dev.testnet latest_key_version | ||
|
||
near view v1.signer-dev.testnet experimental_signature_deposit | ||
|
||
|
||
## Node API | ||
|
||
near call v1.signer-dev.testnet respond '{"request":{"epsilon":{"scalar":"72DB59A313FA266B1C3B40F20325C9023DDC564E7790363BCC2AE76580339648"},"payload_hash":{"scalar":"05FCB4470106774DCC5A3C7689FD2917C15AB81B6FA44960843E6389780A5364"}},"response":{"big_r":{"affine_point":"02EC7FA686BB430A4B700BDA07F2E07D6333D9E33AEEF270334EB2D00D0A6FEC6C"},"recovery_id":0,"s":{"scalar":"20F90C540EE00133C911EA2A9ADE2ABBCC7AD820687F75E011DFEEC94DB10CD6"}}}' --accountId alexkushnir.testnet --gas 300000000000000 | ||
|
||
near call v1.signer-dev.testnet join '{"cipher_pk":[59,105,187,93,147,173,85,119,242,237,171,117,87,221,135,181,28,120,239,58,50,198,137,77,219,16,151,195,93,140,92,88],"sign_pk":"ed25519:J75xXmF7WUPS3xCm3hy2tgwLCKdYM1iJd4BWF8sWVnae","url":"http://localhost:3030"}' --accountId alexkushnir.testnet --gas 300000000000000 | ||
|
||
near call v1.signer-dev.testnet vote_join '{"candidate":"alexkushnir.testnet"}' --accountId alexkushnir.testnet --gas 300000000000000 | ||
|
||
near call v1.signer-dev.testnet vote_leave '{"kick":"alexkushnir.testnet"}' --accountId alexkushnir.testnet --gas 300000000000000 | ||
|
||
near call v1.signer-dev.testnet vote_pk '{"public_key": ed25519:J75xXmF7WUPS3xCm3hy2tgwLCKdYM1iJd4BWF8sWVnae}' --accountId alexkushnir.testnet --gas 300000000000000 | ||
|
||
near call v1.signer-dev.testnet vote_reshared '{"epoch": 1}' --accountId alexkushnir.testnet --gas 300000000000000 | ||
|
||
near call v1.signer-dev.testnet propose_update --base64 "AAHgkwQAAAAAAADdbQAAAAAAAgAAAEAAAAAABAAAAABAAMAnCQAAAAAAAAAAAAACAAAAACAAyK8AAAAAAAAAAAAAyK8AAAAAAABADQMAAAAAAABcJgUAAAAAAAAAAAAAAAAAAAAA" --accountId alexkushnir.testnet --gas 300000000000000 | ||
|
||
near call v1.signer-dev.testnet vote_update '{"id": 0}' --accountId alexkushnir.testnet --gas 300000000000000 | ||
|
||
|
||
## Contract developer helper API | ||
|
||
near call v1.signer-dev.testnet init '{"candidates":{"candidates":{"alice.near":{"account_id":"alice.near","cipher_pk":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],"sign_pk":"ed25519:J75xXmF7WUPS3xCm3hy2tgwLCKdYM1iJd4BWF8sWVnae","url":"127.0.0.1"},"bob.near":{"account_id":"bob.near","cipher_pk":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],"sign_pk":"ed25519:J75xXmF7WUPS3xCm3hy2tgwLCKdYM1iJd4BWF8sWVnae","url":"127.0.0.1"},"caesar.near":{"account_id":"caesar.near","cipher_pk":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],"sign_pk":"ed25519:J75xXmF7WUPS3xCm3hy2tgwLCKdYM1iJd4BWF8sWVnae","url":"127.0.0.1"}}},"threshold":1}' --accountId alexkushnir.testnet --gas 300000000000000 | ||
|
||
near call v1.signer-dev.testnet init_running '{"epoch":0,"participants":{"account_to_participant_id":{"alice.near":0,"bob.near":1,"caesar.near":2},"next_id":3,"participants":{"alice.near":{"account_id":"alice.near","cipher_pk":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],"sign_pk":"ed25519:J75xXmF7WUPS3xCm3hy2tgwLCKdYM1iJd4BWF8sWVnae","url":"127.0.0.1"},"bob.near":{"account_id":"bob.near","cipher_pk":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],"sign_pk":"ed25519:J75xXmF7WUPS3xCm3hy2tgwLCKdYM1iJd4BWF8sWVnae","url":"127.0.0.1"},"caesar.near":{"account_id":"caesar.near","cipher_pk":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],"sign_pk":"ed25519:J75xXmF7WUPS3xCm3hy2tgwLCKdYM1iJd4BWF8sWVnae","url":"127.0.0.1"}}},"public_key":"ed25519:J75xXmF7WUPS3xCm3hy2tgwLCKdYM1iJd4BWF8sWVnae","threshold":2}' --accountId alexkushnir.testnet --gas 300000000000000 | ||
|
||
near view v1.signer-dev.testnet migrate | ||
|
||
near view v1.signer-dev.testnet state | ||
|
||
near view v1.signer-dev.testnet config | ||
|
||
near view v1.signer-dev.testnet version | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,164 @@ | ||
use std::str::FromStr; | ||
|
||
use crypto_shared::{ScalarExt, SerializableAffinePoint, SerializableScalar, SignatureResponse}; | ||
use k256::Scalar; | ||
use mpc_contract::{ | ||
config::Config, | ||
primitives::{CandidateInfo, Candidates, Participants, SignRequest, SignatureRequest}, | ||
update::ProposeUpdateArgs, | ||
}; | ||
use mpc_keys::hpke; | ||
use near_account_id::AccountId; | ||
use near_primitives::borsh; | ||
use near_sdk::PublicKey; | ||
use serde_json::json; | ||
|
||
const PAYLOAD: [u8; 32] = [ | ||
12, 1, 2, 0, 4, 5, 6, 8, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, | ||
26, 27, 28, 29, 30, 44, | ||
]; | ||
|
||
const SIGN_PK: &str = "ed25519:J75xXmF7WUPS3xCm3hy2tgwLCKdYM1iJd4BWF8sWVnae"; | ||
|
||
pub fn sing_command(contract_id: &AccountId, caller_id: &AccountId) -> anyhow::Result<String> { | ||
let sign_request = SignRequest { | ||
payload: PAYLOAD, | ||
path: "test".into(), | ||
key_version: 0, | ||
}; | ||
|
||
let request_json = format!( | ||
"'{}'", | ||
serde_json::to_string(&json!({"request": sign_request}))? | ||
); | ||
|
||
Ok(format!( | ||
"near call {} sign {} --accountId {} --gas 300000000000000 --deposit 1", | ||
contract_id, request_json, caller_id | ||
)) | ||
} | ||
|
||
pub fn respond_command(contract_id: &AccountId, caller_id: &AccountId) -> anyhow::Result<String> { | ||
let payload_hashed = web3::signing::keccak256(&PAYLOAD); | ||
|
||
let request = SignatureRequest::new( | ||
Scalar::from_bytes(payload_hashed) | ||
.ok_or_else(|| anyhow::anyhow!("Failed to convert bytes to Scalar"))?, | ||
caller_id, | ||
"test", | ||
); | ||
|
||
let big_r = serde_json::from_value( | ||
"02EC7FA686BB430A4B700BDA07F2E07D6333D9E33AEEF270334EB2D00D0A6FEC6C".into(), | ||
)?; // Fake BigR | ||
let s = serde_json::from_value( | ||
"20F90C540EE00133C911EA2A9ADE2ABBCC7AD820687F75E011DFEEC94DB10CD6".into(), | ||
)?; // Fake S | ||
|
||
let response = SignatureResponse { | ||
big_r: SerializableAffinePoint { | ||
affine_point: big_r, | ||
}, | ||
s: SerializableScalar { scalar: s }, | ||
recovery_id: 0, | ||
}; | ||
|
||
let request_json = format!( | ||
"'{}'", | ||
serde_json::to_string(&json!({"request": request, "response": response})).unwrap() | ||
); | ||
|
||
Ok(format!( | ||
"near call {} respond {} --accountId {} --gas 300000000000000", | ||
contract_id, request_json, caller_id | ||
)) | ||
} | ||
|
||
pub fn join_command(contract_id: &AccountId, caller_id: &AccountId) -> anyhow::Result<String> { | ||
let url = "http://localhost:3030"; | ||
let (_, cipher_pk) = hpke::generate(); | ||
let sign_pk = PublicKey::from_str(SIGN_PK)?; | ||
|
||
let join_json = format!( | ||
"'{}'", | ||
serde_json::to_string(&json!({"url": url, "cipher_pk": cipher_pk, "sign_pk": sign_pk}))? | ||
); | ||
|
||
Ok(format!( | ||
"near call {} join {} --accountId {} --gas 300000000000000", | ||
contract_id, join_json, caller_id | ||
)) | ||
} | ||
|
||
pub fn proposed_updates_command( | ||
contract_id: &AccountId, | ||
caller_id: &AccountId, | ||
) -> anyhow::Result<String> { | ||
let args = ProposeUpdateArgs { | ||
code: None, | ||
config: Some(Config::default()), | ||
}; | ||
|
||
let borsh_args = borsh::to_vec(&args)?; | ||
|
||
let base64_encoded = near_primitives::serialize::to_base64(borsh_args.as_slice()); | ||
|
||
Ok(format!( | ||
"near call {} propose_update --base64 {:?} --accountId {} --gas 300000000000000", | ||
contract_id, base64_encoded, caller_id | ||
)) | ||
} | ||
|
||
pub fn init_command(contract_id: &AccountId, caller_id: &AccountId) -> anyhow::Result<String> { | ||
let threshold: usize = 1; | ||
let candidates: Candidates = dummy_candidates(); | ||
|
||
let init_json = format!( | ||
"'{}'", | ||
serde_json::to_string(&json!({"threshold": threshold, "candidates": candidates}))? | ||
); | ||
|
||
Ok(format!( | ||
"near call {} init {} --accountId {} --gas 300000000000000", | ||
contract_id, init_json, caller_id | ||
)) | ||
} | ||
|
||
pub fn init_running_command( | ||
contract_id: &AccountId, | ||
caller_id: &AccountId, | ||
) -> anyhow::Result<String> { | ||
let init_running_json = format!( | ||
"'{}'", | ||
serde_json::to_string( | ||
&json!({"epoch": 0, "participants": Participants::from(dummy_candidates()), "threshold": 2,"public_key": PublicKey::from_str(SIGN_PK)? }) | ||
)? | ||
); | ||
|
||
Ok(format!( | ||
"near call {} init_running {} --accountId {} --gas 300000000000000", | ||
contract_id, init_running_json, caller_id | ||
)) | ||
} | ||
|
||
pub fn dummy_candidates() -> Candidates { | ||
let mut candidates = Candidates::new(); | ||
let names: Vec<AccountId> = vec![ | ||
"alice.near".parse().unwrap(), | ||
"bob.near".parse().unwrap(), | ||
"caesar.near".parse().unwrap(), | ||
]; | ||
|
||
for account_id in names { | ||
candidates.insert( | ||
account_id.clone(), | ||
CandidateInfo { | ||
account_id, | ||
url: "127.0.0.1".into(), | ||
cipher_pk: [0; 32], | ||
sign_pk: PublicKey::from_str(SIGN_PK).unwrap(), | ||
}, | ||
); | ||
} | ||
candidates | ||
} |
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is no mistake, it should be
v1.sigenr-prod.testnet
.