Skip to content

Commit

Permalink
crypto: Use Bech32 encoding for SuiAddress
Browse files Browse the repository at this point in the history
  • Loading branch information
joyqvq committed Nov 3, 2022
1 parent bcbef7f commit 4412e1b
Show file tree
Hide file tree
Showing 35 changed files with 411 additions and 400 deletions.
12 changes: 10 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ move-bytecode-utils = { git = "https://github.com/move-language/move", rev = "be
move-bytecode-verifier = { git = "https://github.com/move-language/move", rev = "be52c7118aeb94fbbfa12590e420a75e8ddfec93" }
move-cli = { git = "https://github.com/move-language/move", rev = "be52c7118aeb94fbbfa12590e420a75e8ddfec93" }
move-compiler = { git = "https://github.com/move-language/move", rev = "be52c7118aeb94fbbfa12590e420a75e8ddfec93" }
move-core-types = { git = "https://github.com/move-language/move", rev = "be52c7118aeb94fbbfa12590e420a75e8ddfec93", features = ["address20"] }
move-core-types = { git = "https://github.com/move-language/move", rev = "be52c7118aeb94fbbfa12590e420a75e8ddfec93", features = ["address32"] }
move-disassembler = { git = "https://github.com/move-language/move", rev = "be52c7118aeb94fbbfa12590e420a75e8ddfec93" }
move-package = { git = "https://github.com/move-language/move", rev = "be52c7118aeb94fbbfa12590e420a75e8ddfec93" }
move-stdlib = { git = "https://github.com/move-language/move", rev = "be52c7118aeb94fbbfa12590e420a75e8ddfec93" }
Expand Down
20 changes: 10 additions & 10 deletions apps/explorer/src/pages/validators/mockData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,52 +17,52 @@ const validators: TestValidatorInfo[] = [
{
name: 'Jump Crypto',
stake: BigInt(9_220_000),
suiAddress: '0x693447224cf96c7b1f8de90d15198ceea22439e5',
suiAddress: 'sui1zupu00ayxqddcu3vrthm2ppe9409r504fqn7cjwl9lpmsjufqjhss6yl72',
},
{
name: 'Blockdaemon',
stake: BigInt(8_220_000),
suiAddress: '0x4497a41750e240f7a3352215c78b1e8ce9d605c1',
suiAddress: 'sui1r8e5df4tf99jwuf6s0n8mkdauspfcq3yd3xd5twej7e2qlshwamqyt60u9',
},
{
name: 'Kraken',
stake: BigInt(4_650_000),
suiAddress: '0xdb3d8f18e40e7fdcb4a3179e029044595e33cf76',
suiAddress: 'sui1tqdprxn9wmfm2q44m3ruthjf0dm5u6x2cdm3n2py44a57ete07gsg5xll6',
},
{
name: 'Coinbase',
stake: BigInt(4_550_000),
suiAddress: '0xf2f70c204eed5c33a9bb3eb4c0e3048edbbc3ac3',
suiAddress: 'sui1w9zfmw8lgxx6ngq9gc2r05yxh8c0lthws0zz72fgzmvgs8gdu4cqsdwhs2',
},
{
name: 'a16z',
stake: BigInt(2_860_000),
suiAddress: '0xf446d537680e4601f8fdc922ab897cc78f3706d7',
suiAddress: 'sui1sau0w2w6j38k2tqtx0t87w9uaackz4gq5qagletswavsnc3n59ksjtk7gf',
},
{
name: 'Figment',
stake: BigInt(2_840_000),
suiAddress: '0x1c83e3c2fe69dd15f60633cf072c3840adef504b',
suiAddress: 'sui1nm3vwhtt858whaa5w3gepanuhqprujaq8vdsksq8a0usyv3mjxjq9nz5fq',
},
{
name: 'Another One',
stake: BigInt(2_730_000),
suiAddress: '0x62afdd1fb17dbeb5325a0f3f6d073ba05bf1b958',
suiAddress: 'sui1hexrm8m3zre03hjl5t8psga34427ply4kz29dze62w8zrkjlt9esv4rnx2',
},
{
name: 'Someone Else',
stake: BigInt(2_730_000),
suiAddress: '0xdd0b64b253fe55b71f9784afee2dfa2e8bbd1ab7',
suiAddress: 'sui1cn6rfe7l2ngxtuwy4z2kpcaktljyghwh3c7jzevxh5w223dzpgxqz7l4hf',
},
{
name: '4Pool',
stake: BigInt(2_730_000),
suiAddress: '0xd4394c1577ca125630f652428d071a7b7dd047ad',
suiAddress: 'sui1mne690jmzjda8jj34cmsd6kju5vlct88azu3z8q5l2jf7yk9f24sdu9738',
},
{
name: '3Pool',
stake: BigInt(2_730_000),
suiAddress: '0xb0ecf49920c6a46104e94d810a9e81db17a6e866',
suiAddress: 'sui1mne690jmzjda8jj34cmsd6kju5vlct88azu3z8q5l2jf7yk9f24sdu9738',
},
];

Expand Down
3 changes: 1 addition & 2 deletions apps/explorer/src/utils/stringUtils.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
// Copyright (c) Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0

import type { SuiAddress } from '@mysten/sui.js';
import { SuiAddress, SUI_ADDRESS_LENGTH } from '@mysten/sui.js';

const IPFS_START_STRING = 'https://ipfs.io/ipfs/';
const SUI_ADDRESS_LENGTH = 20;

export function hexToAscii(hex: string) {
if (!hex || typeof hex != 'string') return;
Expand Down
5 changes: 0 additions & 5 deletions apps/wallet/src/ui/app/components/address-input/validation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,6 @@ export const SUI_ADDRESS_VALIDATION = Yup.string()
.ensure()
.trim()
.required()
.transform((value: string) =>
value.startsWith('0x') || value === '' || value === '0'
? value
: `0x${value}`
)
.test(
'is-sui-address',
// eslint-disable-next-line no-template-curly-in-string
Expand Down
15 changes: 6 additions & 9 deletions crates/sui-json/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ use serde::{Deserialize, Serialize};
use serde_json::{json, Number, Value as JsonValue};
use std::collections::VecDeque;
use std::fmt::{Debug, Formatter};
use sui_types::base_types::{decode_bytes_hex, ObjectID, SuiAddress};
use std::str::FromStr;
use sui_types::base_types::{ObjectID, SuiAddress};
use sui_types::move_package::MovePackage;
use sui_verifier::entry_points_verifier::{
is_tx_context, RESOLVED_ASCII_STR, RESOLVED_STD_OPTION, RESOLVED_SUI_ID, RESOLVED_UTF8_STR,
Expand Down Expand Up @@ -198,14 +199,10 @@ impl SuiJsonValue {
)
}

(JsonValue::String(s), MoveTypeLayout::Address) => {
let s = s.trim().to_lowercase();
if !s.starts_with(HEX_PREFIX) {
bail!("Address hex string must start with 0x.",);
}
let r: SuiAddress = decode_bytes_hex(&s)?;
MoveValue::Address(r.into())
}
(JsonValue::String(s), MoveTypeLayout::Address) => match SuiAddress::from_str(s) {
Ok(a) => MoveValue::Address(a.into()),
Err(e) => bail!("Invalid address {e} {s}"),
},
_ => bail!("Unexpected arg {val} for expected type {ty}"),
})
}
Expand Down
8 changes: 4 additions & 4 deletions crates/sui-json/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -477,8 +477,8 @@ fn test_basic_args_linter_top_level() {
let address = SuiAddress::random_for_testing_only();

let value = json!(value_raw);
// Encode as hex string
let addr = json!(format!("0x{:02x}", address));
// Encode as bech32 string
let addr = json!(format!("{}", address));

// They have to be ordered
let args = vec![value, addr]
Expand Down Expand Up @@ -513,8 +513,8 @@ fn test_basic_args_linter_top_level() {
let address = SuiAddress::random_for_testing_only();

let object_id = json!(format!("0x{:02x}", object_id_raw));
// Encode as hex string
let addr = json!(format!("0x{:02x}", address));
// Encode as Bech32 string
let addr = json!(format!("{}", address));

// They have to be ordered
let args = vec![object_id, addr]
Expand Down
2 changes: 1 addition & 1 deletion crates/sui-keys/tests/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ fn mnemonic_test() {
#[test]
fn sui_wallet_address_mnemonic_test() -> Result<(), anyhow::Error> {
let phrase = "result crisp session latin must fruit genuine question prevent start coconut brave speak student dismiss";
let expected_address = SuiAddress::from_str("0x1a4623343cd42be47d67314fce0ad042f3c82685")?;
let expected_address = SuiAddress::from_str("sui16xr5u5tya830w2szngx95tfav3jw56nhjhxwen")?;

let temp_dir = TempDir::new().unwrap();
let keystore_path = temp_dir.path().join("sui.keystore");
Expand Down
Loading

0 comments on commit 4412e1b

Please sign in to comment.