Skip to content

Commit

Permalink
chore: format by Prettier Move plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
npty committed Aug 23, 2024
1 parent d86325e commit 1ae9636
Show file tree
Hide file tree
Showing 31 changed files with 5,495 additions and 4,944 deletions.
524 changes: 265 additions & 259 deletions move/abi/sources/abi.move

Large diffs are not rendered by default.

396 changes: 208 additions & 188 deletions move/axelar_gateway/sources/auth.move

Large diffs are not rendered by default.

459 changes: 232 additions & 227 deletions move/axelar_gateway/sources/channel.move

Large diffs are not rendered by default.

541 changes: 272 additions & 269 deletions move/axelar_gateway/sources/discovery.move

Large diffs are not rendered by default.

621 changes: 323 additions & 298 deletions move/axelar_gateway/sources/gateway.move

Large diffs are not rendered by default.

92 changes: 46 additions & 46 deletions move/axelar_gateway/sources/types/bytes32.move
Original file line number Diff line number Diff line change
@@ -1,62 +1,62 @@
module axelar_gateway::bytes32 {
use sui::bcs::BCS;
use sui::address;
module axelar_gateway::bytes32;

// -----
// Types
// -----
use sui::address;
use sui::bcs::BCS;

public struct Bytes32 has copy, drop, store {
bytes: address,
}
// -----
// Types
// -----

// ---------
// Constants
// ---------
public struct Bytes32 has copy, drop, store {
bytes: address,
}

const LENGTH: u64 = 32;
// ---------
// Constants
// ---------

// ----------------
// Public Functions
// ----------------
const LENGTH: u64 = 32;

/// Casts an address to a bytes32
public fun new(bytes: address): Bytes32 {
Bytes32{bytes: bytes}
}
// ----------------
// Public Functions
// ----------------

public fun default(): Bytes32 {
Bytes32{bytes: @0x0}
}
/// Casts an address to a bytes32
public fun new(bytes: address): Bytes32 {
Bytes32 { bytes: bytes }
}

public fun from_bytes(bytes: vector<u8>): Bytes32 {
new(address::from_bytes(bytes))
}
public fun default(): Bytes32 {
Bytes32 { bytes: @0x0 }
}

public fun from_address(addr: address): Bytes32 {
new(addr)
}
public fun from_bytes(bytes: vector<u8>): Bytes32 {
new(address::from_bytes(bytes))
}

public fun to_bytes(self: Bytes32): vector<u8> {
self.bytes.to_bytes()
}
public fun from_address(addr: address): Bytes32 {
new(addr)
}

public fun length(_self: &Bytes32): u64 {
LENGTH
}
public fun to_bytes(self: Bytes32): vector<u8> {
self.bytes.to_bytes()
}

public fun length(_self: &Bytes32): u64 {
LENGTH
}

public(package) fun peel(bcs: &mut BCS): Bytes32 {
new(bcs.peel_address())
}
public(package) fun peel(bcs: &mut BCS): Bytes32 {
new(bcs.peel_address())
}

// -----
// Tests
// -----
// -----
// Tests
// -----

#[test]
public fun test_new() {
let actual = new(@0x1);
#[test]
public fun test_new() {
let actual = new(@0x1);

assert!(actual.to_bytes() == @0x1.to_bytes(), 0);
}
assert!(actual.to_bytes() == @0x1.to_bytes(), 0);
}
126 changes: 64 additions & 62 deletions move/axelar_gateway/sources/types/message.move
Original file line number Diff line number Diff line change
@@ -1,74 +1,76 @@
module axelar_gateway::message {
use std::ascii::String;
use sui::bcs::{Self, BCS};
use sui::hash;
module axelar_gateway::message;

use axelar_gateway::bytes32::{Self, Bytes32};
use axelar_gateway::bytes32::{Self, Bytes32};
use std::ascii::String;
use sui::bcs::{Self, BCS};
use sui::hash;

/// -----
/// Types
/// -----
/// Cross chain message type
public struct Message has copy, drop, store {
source_chain: String,
message_id: String,
source_address: String,
destination_id: address,
payload_hash: Bytes32,
}
/// -----
/// Types
/// -----
/// Cross chain message type
public struct Message has copy, drop, store {
source_chain: String,
message_id: String,
source_address: String,
destination_id: address,
payload_hash: Bytes32,
}

/// -----------------
/// Public Functions
/// -----------------
public fun new(
source_chain: String,
message_id: String,
source_address: String,
destination_id: address,
payload_hash: Bytes32,
): Message {
Message {
source_chain,
message_id,
source_address,
destination_id,
payload_hash,
}
/// -----------------
/// Public Functions
/// -----------------
public fun new(
source_chain: String,
message_id: String,
source_address: String,
destination_id: address,
payload_hash: Bytes32,
): Message {
Message {
source_chain,
message_id,
source_address,
destination_id,
payload_hash,
}
}

/// -----------------
/// Package Functions
/// -----------------
public(package) fun peel(bcs: &mut BCS): Message {
// TODO: allow UTF-8 strings? Or keep it as more generic bytes?
let source_chain = bcs.peel_vec_u8().to_ascii_string();
let message_id = bcs.peel_vec_u8().to_ascii_string();
let source_address = bcs.peel_vec_u8().to_ascii_string();
let destination_id = bcs.peel_address();
let payload_hash = bytes32::peel(bcs);
/// -----------------
/// Package Functions
/// -----------------
public(package) fun peel(bcs: &mut BCS): Message {
// TODO: allow UTF-8 strings? Or keep it as more generic bytes?
let source_chain = bcs.peel_vec_u8().to_ascii_string();
let message_id = bcs.peel_vec_u8().to_ascii_string();
let source_address = bcs.peel_vec_u8().to_ascii_string();
let destination_id = bcs.peel_address();
let payload_hash = bytes32::peel(bcs);

Message {
source_chain,
message_id,
source_address,
destination_id,
payload_hash,
}
Message {
source_chain,
message_id,
source_address,
destination_id,
payload_hash,
}
}

public(package) fun message_to_command_id(source_chain: String, message_id: String): Bytes32 {
let mut id = source_chain.into_bytes();
id.append(b"_");
id.append(message_id.into_bytes());
public(package) fun message_to_command_id(
source_chain: String,
message_id: String,
): Bytes32 {
let mut id = source_chain.into_bytes();
id.append(b"_");
id.append(message_id.into_bytes());

bytes32::from_bytes(hash::keccak256(&id))
}
bytes32::from_bytes(hash::keccak256(&id))
}

public(package) fun command_id(self: &Message): Bytes32 {
message_to_command_id(self.source_chain, self.message_id)
}
public(package) fun command_id(self: &Message): Bytes32 {
message_to_command_id(self.source_chain, self.message_id)
}

public(package) fun hash(self: &Message): Bytes32 {
bytes32::from_bytes(hash::keccak256(&bcs::to_bytes(self)))
}
public(package) fun hash(self: &Message): Bytes32 {
bytes32::from_bytes(hash::keccak256(&bcs::to_bytes(self)))
}
132 changes: 67 additions & 65 deletions move/axelar_gateway/sources/types/proof.move
Original file line number Diff line number Diff line change
@@ -1,84 +1,86 @@
module axelar_gateway::proof {
use sui::bcs::BCS;
use sui::ecdsa_k1 as ecdsa;
module axelar_gateway::proof;

use axelar_gateway::weighted_signers::{Self, WeightedSigners};
use axelar_gateway::weighted_signers::{Self, WeightedSigners};
use sui::bcs::BCS;
use sui::ecdsa_k1 as ecdsa;

// -----
// Types
// -----
public struct Signature has copy, drop, store {
bytes: vector<u8>,
}
// -----
// Types
// -----
public struct Signature has copy, drop, store {
bytes: vector<u8>,
}

public struct Proof has copy, drop, store {
signers: WeightedSigners,
signatures: vector<Signature>,
}
public struct Proof has copy, drop, store {
signers: WeightedSigners,
signatures: vector<Signature>,
}

// ---------
// Constants
// ---------
/// Length of the signature
const SIGNATURE_LENGTH: u64 = 65;

// ------
// Errors
// ------
/// Invalid length of the bytes
const EInvalidLength: u64 = 0;

// ----------------
// Public Functions
// ----------------
/// The signers of the proof
public fun signers(proof: &Proof): &WeightedSigners {
&proof.signers
}
// ---------
// Constants
// ---------
/// Length of the signature
const SIGNATURE_LENGTH: u64 = 65;

// ------
// Errors
// ------
/// Invalid length of the bytes
const EInvalidLength: u64 = 0;

// ----------------
// Public Functions
// ----------------
/// The signers of the proof
public fun signers(proof: &Proof): &WeightedSigners {
&proof.signers
}

/// The proof signatures
public fun signatures(proof: &Proof): &vector<Signature> {
&proof.signatures
}
/// The proof signatures
public fun signatures(proof: &Proof): &vector<Signature> {
&proof.signatures
}

// -----------------
// Package Functions
// -----------------
public(package) fun new_signature(bytes: vector<u8>): Signature {
assert!(bytes.length() == SIGNATURE_LENGTH, EInvalidLength);
// -----------------
// Package Functions
// -----------------
public(package) fun new_signature(bytes: vector<u8>): Signature {
assert!(bytes.length() == SIGNATURE_LENGTH, EInvalidLength);

Signature {
bytes: bytes,
}
Signature {
bytes: bytes,
}
}

/// Recover the public key from an EVM recoverable signature, using keccak256 as the hash function
public(package) fun recover_pub_key(self: &Signature, message: &vector<u8>): vector<u8> {
ecdsa::secp256k1_ecrecover(&self.bytes, message, 0)
}
/// Recover the public key from an EVM recoverable signature, using keccak256 as the hash function
public(package) fun recover_pub_key(
self: &Signature,
message: &vector<u8>,
): vector<u8> {
ecdsa::secp256k1_ecrecover(&self.bytes, message, 0)
}

public(package) fun peel_signature(bcs: &mut BCS): Signature {
let bytes = bcs.peel_vec_u8();
public(package) fun peel_signature(bcs: &mut BCS): Signature {
let bytes = bcs.peel_vec_u8();

new_signature(bytes)
}
new_signature(bytes)
}

public(package) fun peel(bcs: &mut BCS): Proof {
let signers = weighted_signers::peel(bcs);
public(package) fun peel(bcs: &mut BCS): Proof {
let signers = weighted_signers::peel(bcs);

let mut signatures = vector::empty<Signature>();
let mut signatures = vector::empty<Signature>();

let mut length = bcs.peel_vec_length();
let mut length = bcs.peel_vec_length();

while (length > 0) {
signatures.push_back(peel_signature(bcs));
while (length > 0) {
signatures.push_back(peel_signature(bcs));

length = length - 1;
};
length = length - 1;
};

Proof {
signers,
signatures,
}
Proof {
signers,
signatures,
}
}
Loading

0 comments on commit 1ae9636

Please sign in to comment.