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

[explorer + ts-sdk] Search input string type checks #2028

Merged
merged 19 commits into from
May 19, 2022
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
fix import in common.ts
  • Loading branch information
Stella Cannefax committed May 18, 2022
commit 45a06ece0016e06ec80a7eff21159801670d3120
8 changes: 5 additions & 3 deletions sdk/typescript/src/types/common.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// Copyright (c) 2022, Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0

import { Base64DataBuffer } from "../serialization/base64";

/** Base64 string representing the object digest */
export type TransactionDigest = string;
export type SuiAddress = string;
Expand All @@ -19,14 +21,14 @@ const VALID_BASE64_REGEX =
/^(?:[a-zA-Z0-9+\/]{4})*(?:|(?:[a-zA-Z0-9+\/]{3}=)|(?:[a-zA-Z0-9+\/]{2}==)|(?:[a-zA-Z0-9+\/]{1}===))$/;

export function isValidTransactionDigest(value: string): value is TransactionDigest {
return (new Base64DataBuffer(value)).getLength() === TX_DIGEST_LENGTH
return new Base64DataBuffer(value).getLength() === TX_DIGEST_LENGTH
&& VALID_BASE64_REGEX.test(value);
}

// TODO - can we automatically sync this with rust length definition?
// Source of truth is
// https://github.com/MystenLabs/sui/blob/acb2b97ae21f47600e05b0d28127d88d0725561d/crates/sui-types/src/base_types.rs#L67
// which uses the Move account address length
// https://github.com/MystenLabs/sui/blob/acb2b97ae21f47600e05b0d28127d88d0725561d/crates/sui-types/src/base_types.rs#L67
// which uses the Move account address length
// https://github.com/move-language/move/blob/67ec40dc50c66c34fd73512fcc412f3b68d67235/language/move-core/types/src/account_address.rs#L23 .

const SUI_ADDRESS_LENGTH = 20;
Expand Down